farahZ Posted May 15, 2013 Share Posted May 15, 2013 i have a table in mysql/phpmyadmin Food, Size, Calories i concatenated 2 values and its working successfully in the drop down list according to this code: <?PHP $query = "SELECT Food,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['Calories']."</option>"); } ?> i need to show the Size too!!and this code isnt working any help?? while($row = mysqli_fetch_assoc($result)) { echo ("<option VALUE=\"".$row['Food']."\" " . ($food == $row['Food'] ? " selected" : "") . ">".$row['Food'].' - ' .$row['Size']. ' - '.$row['Calories']."</option>"); } Link to comment https://forums.phpfreaks.com/topic/278038-view-several-values-in-a-drop-down-list/ Share on other sites More sharing options...
taquitosensei Posted May 15, 2013 Share Posted May 15, 2013 It looks like you're not selecting the size. SELECT Food,Calories FROM food order by Food On 5/15/2013 at 5:45 PM, farahZ said: i have a table in mysql/phpmyadmin Food, Size, Calories i concatenated 2 values and its working successfully in the drop down list according to this code: <?PHP $query = "SELECT Food,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['Calories']."</option>"); } ?> i need to show the Size too!!and this code isnt working any help?? while($row = mysqli_fetch_assoc($result)) { echo ("<option VALUE=\"".$row['Food']."\" " . ($food == $row['Food'] ? " selected" : "") . ">".$row['Food'].' - ' .$row['Size']. ' - '.$row['Calories']."</option>"); } Link to comment https://forums.phpfreaks.com/topic/278038-view-several-values-in-a-drop-down-list/#findComment-1430265 Share on other sites More sharing options...
farahZ Posted May 15, 2013 Author Share Posted May 15, 2013 thanks .. !!i forget to add it in the query Link to comment https://forums.phpfreaks.com/topic/278038-view-several-values-in-a-drop-down-list/#findComment-1430266 Share on other sites More sharing options...
buzzycoder Posted May 15, 2013 Share Posted May 15, 2013 Better create variables like below: <?php $food = $row['Food']; $size = $row['Size']; $calories = $row['Calories']; ?> And use it easily by just placing variable names. Hope it helps you! Link to comment https://forums.phpfreaks.com/topic/278038-view-several-values-in-a-drop-down-list/#findComment-1430267 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.