From: "Jessica Mays" <[EMAIL PROTECTED]>
> 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.
>
>    while ($i < $num_results)   {
>
> $row = mysql_fetch_array($result);
>
>   $producer = $row["PRODUCE"];
[snip]
> while (  $producer == $row["PRODUCE"]) {
>
> $row = mysql_fetch_array($result);
[snip]
> ++$i;
> }
>
> ++$i;
>    }

You posted too much code to go through easily. It took me a while to figure
out what you were doing. The code above is what it really could have been
condensed to...

Anyhow, the first time through, you're inner while() loop is always going to
execute and keep executing until you pull a new "produce" value from the
result set. At that time, the new "produce" row is currently in $row, the
inner while() loop fails and control passes back to your outer loop.
However, at that time you call mysql_fetch_array() again in your outer loop
and you just lost the row that cause the inner loop to teminate.

What you want, if I can read right, is to only display the part in your
outer while() loop when "produce" changes.

$producer = '';
while($row = mysql_fetch_array($result))
{
  if($row['produce'] != $producer)
  {
    //display outer while() loop HTML here
    $producer = $row['produce'];
  }
  //display inner while() loop HTML here.
}

Hope that helps.

---John Holmes...

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to