populating drop down menu from MySQL

Reply

Join Date: Jun 2008
Posts: 46
Reputation: akshit is an unknown quantity at this point 
Solved Threads: 0
akshit akshit is offline Offline
Light Poster

populating drop down menu from MySQL

 
0
  #1
Jul 19th, 2008
hi guys.

i hav this drop down menu, which i need to populate with data from one column of a particular table of MySQL dbase.

i hav read a lot on this, but have not been able to come up wid any code.

any and all help in this regard will be greatly appreciated.

thx a ton.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 1,076
Reputation: Shanti Chepuru is on a distinguished road 
Solved Threads: 98
Shanti Chepuru's Avatar
Shanti Chepuru Shanti Chepuru is offline Offline
Veteran Poster

Re: populating drop down menu from MySQL

 
0
  #2
Jul 19th, 2008
Use this code in your application:
  1. <?
  2. $query="SELECT sub_cat_id, sub_cat_name FROM category";
  3.  
  4. /* You can add order by clause to the sql statement if the names are to be displayed in alphabetical order */
  5.  
  6. $result = mysql_query ($query);
  7. echo "<select name=category value=''></option>";
  8. // printing the list box select command
  9.  
  10. while($nt=mysql_fetch_array($result)){//Array or records stored in $nt
  11. echo "<option value=$nt[sub_cat_id]>$nt[sub_cat_name]</option>";
  12. /* Option values are added by looping through the array */
  13. }
  14. echo "</select>";// Closing of list box
  15. ?>
Be intelligent, But Don't try to cheat.. Be innocent But Don't get cheated..
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 1,076
Reputation: Shanti Chepuru is on a distinguished road 
Solved Threads: 98
Shanti Chepuru's Avatar
Shanti Chepuru Shanti Chepuru is offline Offline
Veteran Poster

Re: populating drop down menu from MySQL

 
0
  #3
Jul 19th, 2008
I you want to display the second dropdown from first dropdown,then see this thread:
http://www.daniweb.com/forums/thread77281.html
Be intelligent, But Don't try to cheat.. Be innocent But Don't get cheated..
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 25
Reputation: phobia1 is an unknown quantity at this point 
Solved Threads: 0
phobia1 phobia1 is offline Offline
Light Poster

Could I ask for help please

 
0
  #4
Oct 25th, 2009
Hi to all
I have a drop down list that is populated from my mysql database, and works fine.
How to eliminate duplicate entries. I have seen the answer a 100 times but cant get it to work.
Here is the snip of code that I have
  1. $result = mysql_query ($query);
  2. echo "<select name=Location value=''>Location</option>";
  3. // printing the list box select command
  4.  
  5. while($nt=mysql_fetch_array($result)){//Array or records stored in $nt
  6. echo "<option value=$nt[Town]>$nt[Location]</option>";
  7. /* Option values are added by looping through the array */
  8. }
  9. echo "</select>";// Closing of list box
  10.  
  11. mysql_free_result($result) ;
Last edited by peter_budo; Oct 25th, 2009 at 7:05 pm. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks)
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 25
Reputation: phobia1 is an unknown quantity at this point 
Solved Threads: 0
phobia1 phobia1 is offline Offline
Light Poster
 
0
  #5
Oct 26th, 2009
0. $query="SELECT DISTINCT * FROM Garant GROUP BY Location";

Thanks for all that helped and apologies that I upset the moderators
Reply With Quote Quick reply to this message  
Reply

Message:




Views: 2251 | Replies: 4
Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC