Connecting Tech Pros Worldwide Forums | Help | Site Map

Retriew mysql values to dropdown boxes

Familiar Sight
 
Join Date: Jan 2008
Posts: 199
#1: Sep 10 '09
I have mysql DB with 4 tables.In my php page I have 4 drop down boxes. I want to retrieve db values to each dropdown box.
ex:
Expand|Select|Wrap|Line Numbers
  1. table 1- "vehicles"
  2. table 2- "fruits"
  3. tables 3- "animals"
  4.  
  5. drop down
  6. =============
  7. $sql="SELECT * FROM animals";
  8.         $result=mysql_query($sql);
  9.         $options="";
  10.         while ($row=mysql_fetch_array($result)) 
  11.         {
  12.             $animal=$row["animal"];
  13.                        $type.="<OPTION>".$animal;
  14.  
  15.               }
  16. <td>Animal</td>
  17.     <td>
  18.     <SELECT id="an">
  19.     <OPTION VALUE=0>Animal
  20.     <?=$animal?>
  21.         </SELECT> 
  22.     </td>
  23.     <td>Frite</td>
  24.     <td>
  25.     <SELECT id="fr">
  26.     <OPTION VALUE=0>Fruite
  27.     <?=$make?>
  28.     </SELECT> 
  29.     </td>....
  30.  
How can I do that? Do I need to write sql query and while loop for every dropdown box.?

Reply