fatcat2010 Posted March 27, 2010 Share Posted March 27, 2010 i experts: I created a departments table and populated value as follows SELECT department_id , name,description FROM departments ...the table has Trading department Food department Toy departments However, I don't know how to create a dropdown in the website frontend like this format: ( Mouse over or click "Departments" navigation menu button will trigger a dropdown with list of department names in above mysql "Departments" table. (do i need a javascript to pull out department name from mysql table or sth else? Home Department About Us Trading department Food department Toy departments Link to comment https://forums.phpfreaks.com/topic/196730-how-to-do-a-mysql-database-driven-menu-dropdown/ Share on other sites More sharing options...
siwelis Posted March 27, 2010 Share Posted March 27, 2010 <? $sql = mysql_query("SELECT * FROM departments ORDER BY name DESC"); //mysql database driven select menu sorted alphabetically by name //name form field echo "<select name=\"formfieldname\">\n"; echo "<option value=\"NULL\">Please Select</option>\n"; while($row = mysql_fetch_array($sql)){ //insert value echo "<option value=\"".stripslashes($row[department_id])."\">"; //insert display name echo stripslashes($row[name])."</option>\n"; } echo "</select>\n"; ?> In all fairness, I learned this method by a book written by a phpfreaks member or owner (I just remember seeing this website mentioned in the book). Link to comment https://forums.phpfreaks.com/topic/196730-how-to-do-a-mysql-database-driven-menu-dropdown/#findComment-1032830 Share on other sites More sharing options...
fatcat2010 Posted March 28, 2010 Author Share Posted March 28, 2010 Thank you so much. siwelis, I search lots of place. Have a good weekend! Link to comment https://forums.phpfreaks.com/topic/196730-how-to-do-a-mysql-database-driven-menu-dropdown/#findComment-1032868 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.