Re: problem with a while loop
| From: | John Nichel | Date: | Thu, 06 May 2004 19:05:48 +0000 |
| Subject: | Re: problem with a while loop | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-185548@lists.php.net to get a copy of this message | ||
Jessica Mays wrote:
Try changing the above from.... while ($i < $num_results) {From: jmays@jmays.com Subject: problem with a while loop Date: May 6, 2004 11:25:28 AM EDT To: php-general-digest@lists.php.netHey everybody! I am new to php (and mySQL) and I am working on a php page that links up to a mySQL database. My current code works up to a point, BUT what happens is that I try to have a while loop and check a variable with an inner while loop but it only catches after the first complete cycle. Basically, some producers will only call up one row, but you always get 2 at the minimum with this code below. I have tried lots of different things which all lead to the second row endlessly repeating or the page not loading at all. Any ideas? Please email me directly since I am on the digest. Thanks Jessica (Also, I am new to this list and if this email is in the wrong format I apologize.) CODE : <? $query = "select * from wine where REGION like 'California' order by PRODUCE,DESCRIPT,VINTAGE"; $result = mysql_query($query); $num_results = mysql_num_rows($result); echo "<p>Number of wines found: ".$num_results."</p>"; $i =0; while ($i < $num_results) {$row = mysql_fetch_array($result);$producer = $row["PRODUCE"];<snip>
$row = mysql_fetch_array($result);To.... while ( $row = mysql_fetch_array($result) ) { -- John C. Nichel KegWorks.com 716.856.9675 john@kegworks.com