On Tue, 7 Jan 2003, James Brennan wrote:

> The while statement is only executing correctly for the first run through
> the foreach loop. Why?

It's /real/ hard to tell when you don't give any context or otherwise
explain what it is you want to achieve.  Since the code in fact executes
correctly, we can only explain what's going on in your code, not why it
doesn't work for your needs ...

You while() loop runs through a mysql result set in its entirety the
first time through the foreach() loop and leaves the result pointer at the
end of the result set.  All subsequent runs of the while() loop will start
fetching results from the end of $show_names ... and get /nothing/.

If you want to use all the results out of $show_names again, you have to
reset the result pointer to the beginning of $show_names.  Use
mysql_data_seek().  http://php.net/mysql_data_seek, and see below.

> foreach($desc as $key=>$value) {
>   printf("Show %s Description <select name='show%sDesc'>", $key, $key);
>   echo "<option value = ''></option>";
>   while($row = mysql_fetch_row($show_names)) {
>     printf("<option value='%s'>%s</option>", $row[0], $row[1]);
>   }
    if( mysql_num_rows( $show_names ) > 0 ){
      mysql_data_seek( $show_names, 0 );
    }
>   echo "</select><br>";
> }

        g.luck,
        ~Chris


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

Reply via email to