note 49445 added to control-structures.while

From: Date: Fri, 28 Jan 2005 05:52:21 +0000
Subject: note 49445 added to control-structures.while
Groups: php.notes 
Request: Send a blank email to php-notes+get-84101@lists.php.net to get a copy of this message
For other PHP newbies, such as myself who are new to integrating it in with MySQL, I had a problem, where if I did <? while($arr = mysql_fetch_array(mysql_query("SELECT something,something_else,another_thing FROM some_db"))) { // do something useless } ?> it would be an infinite loop, it took me a while to discover the solution, but I found it. To work around this problem, simply use the following instead: <? $query = mysql_query("SELECT something,something_else,another_thing FROM some_db"); while($arr = mysql_fetch_array($query)) { // do something useless } ?> I'm not sure of the cause of this, but it's an easy work around to whatever it may be. Hope this helps some of the other newbies out there. :) ---- Manual Page -- http://www.php.net/manual/en/control-structures.while.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+49445 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+49445&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+49445&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+49445&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+49445&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+49445&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+49445&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#84101) next »