Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Php Dynamic Dropdown Menu

 
 

Share on Google+Share on Google+

Dynamic Dropdown Menu

Advertisement
Put records from your database in a drop down menu/list box.

Dynamic Dropdown Menu

     

Put records from your database in a drop down menu/list box. You can apply it as a navigator list box. Good for saving your webpage areas or you have many links you don't want to show all of them in your pages.

First of all you need to create a table in your desired database,  you can create and insert values using phpMyAdmin, for details please visit our web page:

Another way to create table is open the mysql console and type the following:

create table car_list

(c_id int auto_increment, c_name varchar(20), primary key(c_id));

After that insert few values like this:

insert into car_list

values(0, 'aston martin');

and so on.

Note: Whenever we select any field as auto_increment, value starts from 1 and automatically increases by 1 with each record.

 

Example:

<HTML>

<head>

<title>Dynamic Drop Down List</title>

</head>

<BODY>

<form id="form1" name="form1" method="post" action="<?php echo $PHP_SELF; ?>">

Car company :

<select name='NEW'>

<option value="">--- Select ---</option>

<?

mysql_connect("localhost","root","");

mysql_select_db("roseindia");

$select="roseindia";

if(isset($select)&&$select!=""){

$select=$_POST['NEW'];

}

?>

<?

$list=mysql_query("select * from car_list order by c_name asc");

while($row_list=mysql_fetch_assoc($list)){

?>

<option value="<? echo $row_list['c_id']; ?>" <? if($row_list['c_id']==$select){ echo "selected"; } ?>><? echo $row_list['c_name']; ?></option>

<?

}

?>

</select>

<input type="submit" name="Submit" value="Select" />

</form>

</body>

</html>

Output:

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: November 19, 2009

Related Tutorials

Discuss: Dynamic Dropdown Menu   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:3
canndy girl
April 6, 2011
submit my comment

Great post. You seem to have a good understanding that how to create a professional drop down menu. When I entering your blog, I felt this. Come on and keep writing your blog will be more attractive. To Your Success!
xxx
May 2, 2012
report

this is bad website
pravin
September 18, 2013
php

function is very hard
DMCA.com