odin365 Posted December 18, 2006 Share Posted December 18, 2006 I am a noob. I am trying to create functionality like the customized search on the University of Maine Summer Session website: http://studentrecords.umaine.edu/soc.htmI have all my data on a MySQL database. My issues is using the drop-downs as a query mechanism and pulling up the data. Despite all the PHP books in front of me, I am lost. One of my books recommends doing the drop downs in Javascript with hidden fields... accessing the php script that is a separate file on the server (I actually did something similar). Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/31117-using-dropdowns-to-query-mysql/ Share on other sites More sharing options...
HuggieBear Posted December 18, 2006 Share Posted December 18, 2006 Something like this would work, just replace the database column and form fields with the names you require.[code]<?php// Connect to the databaseinclude('connect.php');// Query the database to get the values for the dropdown$sql = "SELECT id, name FROM menu_options";$result = mysql_query($sql);if (!$result){ echo "Unable to execute $sql<br>\n" . mysql_error(); // Error if we got no result}// Start the select menuecho "<select name='menu_name'>\n";// Echo each option of the menuwhile ($row = mysql_fetch_array($result, MYSQL_ASSOC)){ echo "<option value='" . $row['id'] . "'>" . $row['name'] . "</option>";}// End the menuecho "</select>";?>[/code]RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/31117-using-dropdowns-to-query-mysql/#findComment-143684 Share on other sites More sharing options...
odin365 Posted December 28, 2006 Author Share Posted December 28, 2006 Thank you Huggie! Sorry for not getting back sooner. I am still trying resolve a few things, but this got me going in the right direction. Quote Link to comment https://forums.phpfreaks.com/topic/31117-using-dropdowns-to-query-mysql/#findComment-149034 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.