note 90075 added to function.pg-fetch-all-columns
| From: | strata_ranger at hotmail dot com | Date: | Sun, 05 Apr 2009 02:43:39 +0000 |
| Subject: | note 90075 added to function.pg-fetch-all-columns | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-152824@lists.php.net to get a copy of this message | ||
Unfortunate that pg_fetch_all_columns() doesn't support fetching a column by its name -- if you
want to do that, you'll need to use pg_field_num() as an intermediary:
For example:
<?php
if ($foo)
$cols = "email_address";
else
$cols = "last_name, middle_init";
$result = pg_query("Select first_name, $info, birthday from users_table");
// Problem -- does column #2 refer to the 'birthday' or 'middle_init' field?
$array = pg_fetch_all_columns($result, 2);
// Won't work, must use a column number instead of its name
$array = pg_fetch_all_columns($result, 'birthday');
// Works
$array = pg_fetch_all_columns($result, pg_field_num($result, 'birthday'));
?>
----
Server IP: 69.147.83.197
Probable Submitter: 76.2.25.104
----
Manual Page -- http://www.php.net/manual/en/function.pg-fetch-all-columns.php
Edit -- https://master.php.net/note/edit/90075
Del: integrated -- https://master.php.net/note/delete/90075/integrated
Del: useless -- https://master.php.net/note/delete/90075/useless
Del: bad code -- https://master.php.net/note/delete/90075/bad+code
Del: spam -- https://master.php.net/note/delete/90075/spam
Del: non-english -- https://master.php.net/note/delete/90075/non-english
Del: in docs -- https://master.php.net/note/delete/90075/in+docs
Del: other reasons-- https://master.php.net/note/delete/90075
Reject -- https://master.php.net/note/reject/90075
Search -- https://master.php.net/manage/user-notes.php