Jump to content

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";
?>
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.