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
https://forums.phpfreaks.com/topic/44641-populate-a-listmenu/
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
https://forums.phpfreaks.com/topic/44641-populate-a-listmenu/#findComment-216814
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.