views:

18

answers:

2

Am attemtping to populate a dropdown menu with the results of my SQL query. The script functions, however I just am unsure of the syntax to add the results into the html dropdown menu. Currently it populates a table with the results. Here is my code:

<?php require_once('Connections/database.php'); ?>
<?php
$q=$_GET["q"];

mysql_select_db($database_db, $database);
$sql="SELECT cat_id, catname FROM categories WHERE cat_id = '".$q."'";

$result = mysql_query($sql);

echo "<table border='1'>
<tr>
<th>Category Name</th>
<th>Category ID</th>
</tr>";

while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['catname'] . "</td>";
  echo "<td>" . $row['cat_id'] . "</td>";

  echo "</tr>";
  }
echo "</table>";

mysql_close($database);
?>
A: 

This should do it:

<select name="input_name">
<?php
    while($row = mysql_fetch_array($result))
        echo "<option value='".$row['cat_id']."'>" . $row['catname'] . "</option>";
?>
</select>
Splashdust
Works like a charm! Thanks!
Parker
A: 

for menu , use

<ul>
<li><a href="#">Home</a></li>
<li><a href="#">Products</a></li>
<li><a href="#">Services</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Contact</a></li>
</ul>



   <ul>
<?php
for(){
?>  
  <li><a href="#">$result[datafield]</a></li> 
}
?>
 </ul>
zod
Thank you!I can use this in my other page.
Parker