Home Php Dynamic Dropdown Menu



Dynamic Dropdown Menu
Posted on: November 19, 2009 at 12:00 AM
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:

Related Tags for Dynamic Dropdown Menu:


More Tutorials from this section

Ask Questions?    Discuss: Dynamic Dropdown Menu   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.