Jump to content

Archived

This topic is now archived and is closed to further replies.

themule

multiple mysql_fetch_array() calls

Recommended Posts

Hello.. I'm trying to populate multiple select boxes with the same query, but only the first iteration works.

<select>
while($row = mysql_fetch_array($myQry)){
  <option>echo $row['name']
}
</select>
**Populates correctly
<select>
while($row = mysql_fetch_array($myQry)){
  <option>echo $row['name']
}
</select>
**No data

Any thoughts?

Share this post


Link to post
Share on other sites
use mysql_data_seek($myQry,0); before while loop

Share this post


Link to post
Share on other sites
i'm going to suggest that you be nicer to your database, and stop making it work so hard.  plug everything from your returned rows into an array and loop through that rather than forcing the database to go through the same set of results over and over:

[code]<?php
while($row = mysql_fetch_array($myQry))
{
  $options[] = $row['name'];
}

echo '<select name="something">';
foreach ($options AS $name)
  echo "<option>$name</option>";
echo '</select>';
?>[/code]

everytime you want to loop through your results, use the foreach() loop on the local $options variable rather than the while() MySQL loop.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.