note 61191 added to function.pg-fetch-object
| From: | robeddielee at hotmail dot com | Date: | Fri, 27 Jan 2006 19:38:40 +0000 |
| Subject: | note 61191 added to function.pg-fetch-object | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-102577@lists.php.net to get a copy of this message | ||
I noticed that many people use FOR loops to extract query data. This is the method I use to extract
data.
<?php
@$members = pg_query($db_conn, 'SELECT id,name FROM boards.members ORDER BY name;');
if ($members AND pg_num_rows($members)) {
while ($member = pg_fetch_object($members)) {
echo $member->name.' ('.$member->id.')';
}
}
?>
If an error occurs (or nothing is returned) in the above code nothing will output. An ELSE clause
can be added to the IF to handle query errors (or nothing being returned). Or a seperate check can
be performed for the event that nothing is returned by using an ELSEIF clause.
I like this method because it doesn't use any temporary counter variables.
----
Server IP: 216.194.113.175
Probable Submitter: 65.118.63.250
----
Manual Page -- http://www.php.net/manual/en/function.pg-fetch-object.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+61191
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+61191&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+61191&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+61191&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+61191&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+61191&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+61191&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+61191&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+61191&report=yes
Search -- http://master.php.net/manage/user-notes.php