Jump to content

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.
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.