Jump to content

Displaying mysql data in dropdown menu with PHP


tdavid

Recommended Posts

I would like to display all the food types in one drop down.  This code displays each type in it's own drop down menu...any help is appreciated.  I think it is a simple html or loop bracket issue.  Thanks.

 

<?php
   $query = "SELECT typeid, foodtype from intlfoodtype";
   $result = mysql_query($query);
   echo "<table class=\"ex3\" border=\"0\">\n";
   while($row=mysql_fetch_array($result, MYSQL_ASSOC))
   {
      $typeid = $row['typeid'];
      $foodtype = $row['foodtype'];
      echo "<tr><td width=\"100\">\n";
      echo "</td><td>\n";
      echo "<select>";
      echo '<option value="'.$typeid.'">'.$foodtype.'</option>';
      echo "</td><td>\n";
      echo "</td></tr>\n";
   }
echo "</select>";
   echo "</tr></table>\n";
?>

 

<?php
   $query = "SELECT typeid, foodtype from intlfoodtype";
   $result = mysql_query($query);

   $options = '';
   while($row=mysql_fetch_array($result, MYSQL_ASSOC))
   {
      $options .= "<option value=\"{$row['typeid']}\">{$row['foodtype']}</option>\n";
   }

   echo "<table class=\"ex3\" border=\"0\">\n";
   echo "  <tr>\n";
   echo "    <td width=\"100\"></td>\n";
   echo "    <td>\n";
   echo "    <select>\n";
   echo      $options;
   echo "    </select>\n";
   echo "    </td><td></td>\n";
   echo "  </tr>\n"
   echo "</table>\n";
?>

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.