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 Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
stockdalep Posted March 28, 2007 Author Share Posted March 28, 2007 Thanks a lot worked great cheers. Quote Link to comment 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.