Jump to content

Populate a list\menu


stockdalep

Recommended Posts

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
Share on other sites

 

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.