themule Posted August 11, 2006 Share Posted August 11, 2006 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 dataAny thoughts? Link to comment https://forums.phpfreaks.com/topic/17247-multiple-mysql_fetch_array-calls/ Share on other sites More sharing options...
sasa Posted August 11, 2006 Share Posted August 11, 2006 use mysql_data_seek($myQry,0); before while loop Link to comment https://forums.phpfreaks.com/topic/17247-multiple-mysql_fetch_array-calls/#findComment-73138 Share on other sites More sharing options...
markt Posted August 11, 2006 Share Posted August 11, 2006 Or how about unsetting $myQry?Or mysql_close() .... Link to comment https://forums.phpfreaks.com/topic/17247-multiple-mysql_fetch_array-calls/#findComment-73168 Share on other sites More sharing options...
themule Posted August 12, 2006 Author Share Posted August 12, 2006 mysql_data_seek worked.. thanks sasa! Link to comment https://forums.phpfreaks.com/topic/17247-multiple-mysql_fetch_array-calls/#findComment-73512 Share on other sites More sharing options...
akitchin Posted August 12, 2006 Share Posted August 12, 2006 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]<?phpwhile($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. Link to comment https://forums.phpfreaks.com/topic/17247-multiple-mysql_fetch_array-calls/#findComment-73515 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.