tdavid Posted August 14, 2013 Share Posted August 14, 2013 I would like to display all the food types in one drop down. This code displays each type in it's own drop down menu...any help is appreciated. I think it is a simple html or loop bracket issue. Thanks. <?php $query = "SELECT typeid, foodtype from intlfoodtype"; $result = mysql_query($query); echo "<table class=\"ex3\" border=\"0\">\n"; while($row=mysql_fetch_array($result, MYSQL_ASSOC)) { $typeid = $row['typeid']; $foodtype = $row['foodtype']; echo "<tr><td width=\"100\">\n"; echo "</td><td>\n"; echo "<select>"; echo '<option value="'.$typeid.'">'.$foodtype.'</option>'; echo "</td><td>\n"; echo "</td></tr>\n"; } echo "</select>"; echo "</tr></table>\n"; ?> Link to comment https://forums.phpfreaks.com/topic/281181-displaying-mysql-data-in-dropdown-menu-with-php/ Share on other sites More sharing options...
Yohanne Posted August 15, 2013 Share Posted August 15, 2013 http://www.w3schools.com/php/php_ajax_database.asp Link to comment https://forums.phpfreaks.com/topic/281181-displaying-mysql-data-in-dropdown-menu-with-php/#findComment-1445093 Share on other sites More sharing options...
Psycho Posted August 15, 2013 Share Posted August 15, 2013 <?php $query = "SELECT typeid, foodtype from intlfoodtype"; $result = mysql_query($query); $options = ''; while($row=mysql_fetch_array($result, MYSQL_ASSOC)) { $options .= "<option value=\"{$row['typeid']}\">{$row['foodtype']}</option>\n"; } echo "<table class=\"ex3\" border=\"0\">\n"; echo " <tr>\n"; echo " <td width=\"100\"></td>\n"; echo " <td>\n"; echo " <select>\n"; echo $options; echo " </select>\n"; echo " </td><td></td>\n"; echo " </tr>\n" echo "</table>\n"; ?> Link to comment https://forums.phpfreaks.com/topic/281181-displaying-mysql-data-in-dropdown-menu-with-php/#findComment-1445096 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.