stockdalep Posted March 28, 2007 Share Posted March 28, 2007 Hi I am trying to populate a list\menu from a database with php if I run the code below it works fine. Except if I want to run it inside the table where I need it then I get the List\menu but its empty ?. <?php include "config.php"; $conn = mysql_connect("$db_host", "$db_user", "$db_pass") or die(mysql_error()); $result = mysql_query("SELECT * FROM area"); //start the select box echo '<select name="select">'; while ($row=mysql_fetch_assoc($result)){ //iterate through outputting options echo '<option value="'.$row['area'].'">'; } //close the select box echo '</select>'; ?> +++++++++++++++++++++++++++++++++++++++++++++++++++++ Inside the table its run as <tr> <th scope="row"><div align="right">Collection Area </div></th> <td> <?php include "config.php"; $conn = mysql_connect("$db_host", "$db_user", "$db_pass") or die(mysql_error()); $result = mysql_query("SELECT * FROM area"); //start the select box echo '<select name="select">'; while ($row=mysql_fetch_assoc($result)){ //iterate through outputting options echo '<option value="'.$row['area'].'">'; } //close the select box echo '</select>'; ?> </td> </tr> Thanks for any help Link to comment https://forums.phpfreaks.com/topic/44641-populate-a-listmenu/ Share on other sites More sharing options...
Steve Angelis Posted March 28, 2007 Share Posted March 28, 2007 echo '<select name="select">'; while ($row=mysql_fetch_assoc($result)){ // tell the database, for each entry add the selected item for($n=0;$n<mysql_num_rows($row);$n++) { //iterate through outputting options echo '<option value="'.$row['area'].'">'; } Give that a shot Link to comment https://forums.phpfreaks.com/topic/44641-populate-a-listmenu/#findComment-216814 Share on other sites More sharing options...
stockdalep Posted March 28, 2007 Author Share Posted March 28, 2007 Thanks a lot worked great cheers. Link to comment https://forums.phpfreaks.com/topic/44641-populate-a-listmenu/#findComment-216837 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.