garyed Posted May 19, 2011 Share Posted May 19, 2011 I'm having a problem with populating a second drop down menu that needs to be identical to the first from a mysql database. I have about 20 items in the DB & I only want to show the first 9. My code is: <select name="a_type" style="width: 175px;"> <option value="" selected="selected"> None selected</option> <?php $i=1; while (($_produce = mysql_fetch_array($result_produce)) && ($i <=9 )) { $produce_type=$_produce["type"]; $produce_id=$_produce["id"]; $i++; ?> <option value="<?php echo $produce_id; ?>"><?php echo $produce_id; ?> - <?php echo $produce_type; ?> </option> <?php } ?> </select> That works fine in my first drop down menu but the second drop down menu with the same exact code will show items starting at 11 & higher instead of 1 to 9. I haven't tried closing the DB & the reopening it which I assume would work but there are a lot of other variables & things I'd have to check to make sure they don't get effected so I'd rather not. Is there a simple way to solve this? Link to comment https://forums.phpfreaks.com/topic/236872-while-statement-in-drop-down-menu/ Share on other sites More sharing options...
wildteen88 Posted May 19, 2011 Share Posted May 19, 2011 You need to reset the internal data pointer. Look into using mysql_data_seek. Link to comment https://forums.phpfreaks.com/topic/236872-while-statement-in-drop-down-menu/#findComment-1217624 Share on other sites More sharing options...
garyed Posted May 20, 2011 Author Share Posted May 20, 2011 I appreciate the help but I've been messing with it all day & still haven't gotten it. I can get the pointer back to whatever number I put in the argument but I just get that same number 8 times. I even tried reset() & that helped a little populating the drop down but it locked up the database. If anyone could show me how to fix my code that would be greatly appreciated. Link to comment https://forums.phpfreaks.com/topic/236872-while-statement-in-drop-down-menu/#findComment-1217887 Share on other sites More sharing options...
wildteen88 Posted May 20, 2011 Share Posted May 20, 2011 Make sure you are using mysql_data_seek() before your second dropdown menu. Do not place it inside the while loop. Link to comment https://forums.phpfreaks.com/topic/236872-while-statement-in-drop-down-menu/#findComment-1218116 Share on other sites More sharing options...
garyed Posted May 21, 2011 Author Share Posted May 21, 2011 I finally got it!! I was using ($_produce,0) as the argument when I needed to use ($result_produce,0). Thanks Link to comment https://forums.phpfreaks.com/topic/236872-while-statement-in-drop-down-menu/#findComment-1218310 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.