RE: [PHP] Looping results problem

From: Date: Thu, 01 May 2003 13:27:39 +0000
Subject: RE: [PHP] Looping results problem
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-145948@lists.php.net to get a copy of this message
> I have the following code in my page to fill a list menu with page > titles and id numbers form a database query: > > //insert form with a list menu > echo "<form name=\"parent\" method=\"post\" > action=\"2.php\">\n"; > echo "<select name=\"pageParent\" id=\"pageParent\">\n"; > > $qry = "SELECT pageID,pageTitle from tblContent where pageChild = 0"; > $qryResult = mysql_query($qry,$conn); > $num_results = mysql_num_rows($qryResult); > for ($i=0; $i<$num_results; $i++){ > $row = mysql_fetch_row($qryResult,$i); Replace the two lines above with: While($row = mysql_fetch_row($qryResult) { Mysql_fetch_row() automatically moves the result set to the next row, and then you're also incrementing $i, that's why you're only getting every other row. ---John W. Holmes... PHP Architect - A monthly magazine for PHP Professionals. Get your copy today. http://www.phparch.com/

« previous php.general (#145948) next »