Jump to content

multiple mysql_fetch_array() calls


themule

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?
Link to comment
https://forums.phpfreaks.com/topic/17247-multiple-mysql_fetch_array-calls/
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.

Archived

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

×
×
  • Create New...

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.