farahZ Posted May 29, 2013 Share Posted May 29, 2013 hey guys!!!i was working on extractinng value from MySql and inserting them in a drop-down list but suddenly i realized i had duplicates in the list!! but no duplicates in the table when i open mysqlthats the whole code please help ( <select name="foodType" onChange="autoSubmit();"> <option VALUE=""></option> <?PHP $query = "SELECT Food, Size, Calories FROM food order by Food"; $result = mysqli_query($con,$query); while($row = mysqli_fetch_assoc($result)) { echo ("<option VALUE=\"".$row['Food']."\" " . ($food == $row['Food'] ? " selected" : "") . ">".$row['Food'].' - ' .$row['Size']. ' - '.$row['Calories']."</option>"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/278541-duplicates-in-the-dropdown-list/ Share on other sites More sharing options...
Solution farahZ Posted May 29, 2013 Author Solution Share Posted May 29, 2013 the table in mysql has: FID---Food---Size---Calories in the dropdown list.. each option has: Food--Size--Calories Quote Link to comment https://forums.phpfreaks.com/topic/278541-duplicates-in-the-dropdown-list/#findComment-1432907 Share on other sites More sharing options...
kicken Posted May 29, 2013 Share Posted May 29, 2013 There is nothing in the code you posted that would cause duplicates in the select box, so if you are seeing them, then you have duplicates in your table, or there is some other code causing them that you have not shown. Quote Link to comment https://forums.phpfreaks.com/topic/278541-duplicates-in-the-dropdown-list/#findComment-1432908 Share on other sites More sharing options...
farahZ Posted May 29, 2013 Author Share Posted May 29, 2013 ya i foundthanks for your help!!! Quote Link to comment https://forums.phpfreaks.com/topic/278541-duplicates-in-the-dropdown-list/#findComment-1432909 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.