By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,967 Members | 1,690 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,967 IT Pros & Developers. It's quick & easy.

Retriew mysql values to dropdown boxes

100+
P: 250
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.?
Sep 10 '09 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.