| | |
populating drop down menu from MySQL
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
Use this code in your application:
php Syntax (Toggle Plain Text)
<? $query="SELECT sub_cat_id, sub_cat_name FROM category"; /* You can add order by clause to the sql statement if the names are to be displayed in alphabetical order */ $result = mysql_query ($query); echo "<select name=category value=''></option>"; // printing the list box select command while($nt=mysql_fetch_array($result)){//Array or records stored in $nt echo "<option value=$nt[sub_cat_id]>$nt[sub_cat_name]</option>"; /* Option values are added by looping through the array */ } echo "</select>";// Closing of list box ?>
Be intelligent, But Don't try to cheat.. Be innocent But Don't get cheated..
I you want to display the second dropdown from first dropdown,then see this thread:
http://www.daniweb.com/forums/thread77281.html
http://www.daniweb.com/forums/thread77281.html
Be intelligent, But Don't try to cheat.. Be innocent But Don't get cheated..
•
•
Join Date: Aug 2007
Posts: 25
Reputation:
Solved Threads: 0
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
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
php Syntax (Toggle Plain Text)
$result = mysql_query ($query); echo "<select name=Location value=''>Location</option>"; // printing the list box select command while($nt=mysql_fetch_array($result)){//Array or records stored in $nt echo "<option value=$nt[Town]>$nt[Location]</option>"; /* Option values are added by looping through the array */ } echo "</select>";// Closing of list box 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)
![]() |
Other Threads in the PHP Forum
- Previous Thread: need help retrieving data from two tables
- Next Thread: Variable variables with dynamic array
Views: 2247 | Replies: 4
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary broken cakephp checkbox class cms code countingeverycharactersfromastring cron curl database date directory display download dynamic echo email error file files folder form forms function functions google href htaccess html image include insert integration ip java javascript joomla limit link login loop mail match menu methods mlm mod_rewrite multiple mysql oop pageing parse paypal pdf php printer problem query radio random recursion regex remote script search select server sessions simple sms soap source space spam speed sql structure syntax system table tutorial update updates upload url validation validator variable video web xml youtube






