note 29033 added to function.mysql-fetch-object

From: Date: Thu, 30 Jan 2003 21:50:01 +0000
Subject: note 29033 added to function.mysql-fetch-object
Groups: php.notes 
Request: Send a blank email to php-notes+get-43156@lists.php.net to get a copy of this message
an addition to the previous... for example getting members from a database: function getAllMembers () { $query = "SELECT * FROM people ORDER BY lname"; $result = mysql_query($query); while($member = mysql_fetch_object($result)){ $members[] = $member; } return $members; } <br><br> DON'T FORGET TO DECLARE THE ARRAY. If you try to cycle through members after the function has been called and you don't declare the array first you will get a horribly (HORRIBLY!) ugly error in your page. Also, if you try to add the object into the members array inside the while condition instead of in the while loop, you will generate one extra empty space in the array due to the last iteration/check. -- http://www.php.net/manual/en/function.mysql-fetch-object.php http://master.php.net/manage/user-notes.php?action=edit+29033 http://master.php.net/manage/user-notes.php?action=delete+29033 http://master.php.net/manage/user-notes.php?action=reject+29033

« previous php.notes (#43156) next »