In article <[EMAIL PROTECTED]>, 
[EMAIL PROTECTED] says...

<SNIP>

> //create a list of editible items
> echo "<form method=3Dpost action=3Dedit.php>";
> echo "<select name=3Did>";
> for ($i=3D0; $i <$num_results; $i++)
> {
>       $row =3D mysql_fetch_array($result);
>       echo "<option value=3D$row[id]> $row[id], =
> $row[productname]</option>";
> }
> echo "</select>";
> echo "<input type=3Dsubmit name=3Dsubmit>";
> echo "</form>";
> ?>=00=00
> 
> Everything is good, Everything is fine, so I decide to put the same=20
> snippet of code in again, this time pointing to a different page -- 
> One=20=
> 
> page lets you edit the fields, the other shows you the final output,=20
> the item from the database featured on a web page.
> 
> <p>preview an endpage:</p>
> 
> <?
> //create a list of editible items
> echo "<form method=3Dpost action=3Dpreview.php>";
> echo "<select name=3Did>";
> for ($i=3D0; $i <$num_results; $i++)
> {
>       $row =3D mysql_fetch_array($result);
>       echo "<option value=3D$row[id]> $row[id], =
> $row[productname]</option>";
> }
> echo "</select>";
> echo "<input type=3Dsubmit name=3Dsubmit>";
> echo "</form>";
> ?>=00=00
> 
> The second instance does not work, I get a select with "," as each=20
> option, no population with the id or productname. Clearly, I don't=20
> understand something here, can anyone tell me what?

Each time you invoke mysql_fetch_array (or any of the functions to get 
data) to fetch a row of data from a mysql result set, a pointer is moved 
to the next row, so that the next call to mysql_fetch_array knows where to 
get its next chunk of information. When you reach the last row in the set, 
the pointer is set to 'beyond end of set' and needs to be repositioned 
before it can usefully point to data. Here you ned to use mysql_data_seek 
to reposition the pointer at the first row so you can again cycle through 
the records you have selected.

For future reference, the same principle applies when looping through an 
array with some of the array handling tools.

And just to make your code a bit more 'readable', you might find the 
extract() function handy for grabbing variable values from a result set.

Cheers
-- 
David Robley
Temporary Kiwi!

Quod subigo farinam

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

Reply via email to