garyed Posted October 5, 2010 Share Posted October 5, 2010 I have two drop down menus in a table side by side being populated exactly the same from a msql database. The first menu populates fine but the second one is blank. They are both supposed to be identical, the same info from the same table so I assume that's my problem. I tried moving the while loop so it encapsulates both drop downs but then it messes up the table structure. I tried changing the name of some of the variables by adding "2" on the end & that didn't work either. Is it because once a while loop is executed it can't be used again on the same instance? Heres my code so far: <tr> <td > <select name="wall_type" size="1" style="width: 175px;" > <?php while ($walls_row=mysql_fetch_array($result_walls)) { $type_name=$walls_row["type"]; $type_id=$walls_row["id"]; ?> <option value="<?php echo $type_id; ?>"><?php echo $type_name; ?> </option> <?php } ?> </select> </td> <td > <select name="wall_type2" size="1" style="width: 175px;"> <?php while ($walls_row2=mysql_fetch_array($result_walls)) { $type_name2=$walls_row2["type"]; $type_id2=$walls_row2["id"]; ?> <option value="<?php echo $type_id2; ?>"><?php echo $type_name2; ?> </option> <?php } ?> </select> </td> </tr> Quote Link to comment https://forums.phpfreaks.com/topic/215210-poulate-multiple-dropdowns-from-mysql/ Share on other sites More sharing options...
BlueSkyIS Posted October 5, 2010 Share Posted October 5, 2010 once you've iterated over mysql_fetch_array($result) once, you can't do it again without resetting the pointer: mysql_data_seek( $result ); personally, i would load the results in an array the first time through, then loop over the array for the second select. just personal preference. Quote Link to comment https://forums.phpfreaks.com/topic/215210-poulate-multiple-dropdowns-from-mysql/#findComment-1119281 Share on other sites More sharing options...
garyed Posted October 5, 2010 Author Share Posted October 5, 2010 Thanks for the help, I'm not sure i understand though (I'm really a novice at this) I don't even know what a pointer is. I thought that "mysql_fetch_array ( $result_walls) " loaded the results into an array. I've got a lot more reading to do. This stuff reminds me of how lost i was when I first started using Linux. The tutorials are great once you get to a certain level but until then its like reading Hieroglyphics. Quote Link to comment https://forums.phpfreaks.com/topic/215210-poulate-multiple-dropdowns-from-mysql/#findComment-1119299 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.