Kathy Posted July 10, 2009 Share Posted July 10, 2009 Can anybody explain to me or send me links to some tutorials on how to populate a drop down menu with a database? What I ultimately want to achieve is to have a drop down box, containing types of businesses populated from a database and depending on what option you choose from the drop down on clicking an option eg. Bakeries this will then populate another drop down, from here you will choose a company name, eg. Margerie's Baked Goods, on clicking this it will bring up contact information, which I'm guessing should be populated in text fields? Link to comment https://forums.phpfreaks.com/topic/165469-how-to-populate-a-drop-down-with-sql/ Share on other sites More sharing options...
milesap Posted July 10, 2009 Share Posted July 10, 2009 Extract the values from the database and put them into an array. You can use the mysql_fetch_array function to achieve this. Then add a foreach loop on the array to print out all the values. Link to comment https://forums.phpfreaks.com/topic/165469-how-to-populate-a-drop-down-with-sql/#findComment-872742 Share on other sites More sharing options...
seventheyejosh Posted July 10, 2009 Share Posted July 10, 2009 like so: $res=mysql_query("SELECT * FROM table WHERE 1"); echo '<select name="name">'; while($row=mysql_fetch_array($res)){ echo "<option value=$row['value']>$row['display']</option>"; } echo '</select>'; Link to comment https://forums.phpfreaks.com/topic/165469-how-to-populate-a-drop-down-with-sql/#findComment-872758 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.