webguync Posted June 6, 2008 Share Posted June 6, 2008 Hello, I currently have a static html dropdown menu coded as such <table id="employees"> <tr> <td> <form action=""> <select name="employees"> <option value="employee1">Employee1</option> <option value="employee2">Employee2</option> <option value="employee3">Employee3</option> <option value="employee4">Employee4</option> </select> </form> </td> </tr> </table> I want to change this to integrate with my MySQL table using PHP my table is right now set up with two columns ID Employee_Name 1 John Smith 2 Bill Jones 3 Tom Turkey 4 Sam Iam so that I can just swap out the table name and ID's whenever i want to generate a new menu. I know how to connect to the database and extract with the SQL, so I would just need help with the menu part to get the data from the MySQL table. thanks in advance. Link to comment https://forums.phpfreaks.com/topic/109020-solved-generating-phpmysql-select-menu/ Share on other sites More sharing options...
GingerRobot Posted June 6, 2008 Share Posted June 6, 2008 Try something like: <?php //connect to db $sql = "SELECT ID,Employee_Name FROM yourtable ORDER BY ID ASC"; $result = mysql_query($sql) or die(mysql_error()); echo '<select>'; while(list($id,$name) = mysql_fetch_row($result)){ echo '<option value="'.$id.'" />'.$name.'</option>'."\n"; } echo '</select>'; ?> Link to comment https://forums.phpfreaks.com/topic/109020-solved-generating-phpmysql-select-menu/#findComment-559250 Share on other sites More sharing options...
zero_ZX Posted June 6, 2008 Share Posted June 6, 2008 Thanks alot, works perfectly, i needed it. Link to comment https://forums.phpfreaks.com/topic/109020-solved-generating-phpmysql-select-menu/#findComment-559262 Share on other sites More sharing options...
webguync Posted June 6, 2008 Author Share Posted June 6, 2008 worked for me too, thanks! Link to comment https://forums.phpfreaks.com/topic/109020-solved-generating-phpmysql-select-menu/#findComment-559295 Share on other sites More sharing options...
GingerRobot Posted June 6, 2008 Share Posted June 6, 2008 lol -- it's not often you solve two people's problem with the same post If you're happy, can you mark the topic as solved please? Link to comment https://forums.phpfreaks.com/topic/109020-solved-generating-phpmysql-select-menu/#findComment-559301 Share on other sites More sharing options...
Vacman Posted June 9, 2008 Share Posted June 9, 2008 Note: http://www.phpfreaks.com/forums/index.php/topic,201057.0.html This is related to my question, but I need to not only do this but to select a value from another field in the db and populate the pull-down with the info and have the first item be my value from that other field... make sense? Link to comment https://forums.phpfreaks.com/topic/109020-solved-generating-phpmysql-select-menu/#findComment-560884 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.