Introduction
A Dropdown list is a combination of items in a list. In the dropdown list menu only the title is visible but not the contents. The contents are shown only when the user activates it by a small arrow. The user may select an item from the menu by dragging the mouse from the menu title or by clicking the title and then clicking the item. The dropdown list box is read-only. We can say a drop down list is a box containing a list of multiple items. A drop-down list is a list in which the selected item is always visible, and the others are visible on demand by clicking a drop-down button.
Step 1. First of all we create a database in MySql using the following query.
CREATE DATABASE `company`;
Step 2. After that then we create a table in the database. For create table in the database you can use the following query.
CREATE TABLE `company`.`employee` (`emp_id` INT(10) NOT NULL AUTO_INCREMENT, `emp_name` VARCHAR(30) NOT NULL,
PRIMARY KEY(`emp_id`)) ENGINE = InnoDB;
Step 3. Now we insert the values in the table using the following queries.
insert into employee (emp_id,emp_name) values(0,'Vineet Saini');
insert into employee (emp_id,emp_name) values(0,'Sumit Sharma');
insert into employee (emp_id,emp_name) values(0,'Dorilal Agarwal');
insert into employee (emp_id,emp_name) values(0,'Omveer Singh');
insert into employee (emp_id,emp_name) values(0,'Maneesh Tewatia');
insert into employee (emp_id,emp_name) values(0,'Rohtash Kumar');
insert into employee (emp_id,emp_name) values(0,'Priyanka Sachan');
insert into employee (emp_id,emp_name) values(0,'Neha Saini');
Step 4. When we execute the above query then you will get the following table.
A Dropdown list is a combination of items in a list. In the dropdown list menu only the title is visible but not the contents. The contents are shown only when the user activates it by a small arrow. The user may select an item from the menu by dragging the mouse from the menu title or by clicking the title and then clicking the item. The dropdown list box is read-only. We can say a drop down list is a box containing a list of multiple items. A drop-down list is a list in which the selected item is always visible, and the others are visible on demand by clicking a drop-down button.
Step 1. First of all we create a database in MySql using the following query.
CREATE DATABASE `company`;
Step 2. After that then we create a table in the database. For create table in the database you can use the following query.
CREATE TABLE `company`.`employee` (`emp_id` INT(10) NOT NULL AUTO_INCREMENT, `emp_name` VARCHAR(30) NOT NULL,
PRIMARY KEY(`emp_id`)) ENGINE = InnoDB;
Step 3. Now we insert the values in the table using the following queries.
insert into employee (emp_id,emp_name) values(0,'Vineet Saini');
insert into employee (emp_id,emp_name) values(0,'Sumit Sharma');
insert into employee (emp_id,emp_name) values(0,'Dorilal Agarwal');
insert into employee (emp_id,emp_name) values(0,'Omveer Singh');
insert into employee (emp_id,emp_name) values(0,'Maneesh Tewatia');
insert into employee (emp_id,emp_name) values(0,'Rohtash Kumar');
insert into employee (emp_id,emp_name) values(0,'Priyanka Sachan');
insert into employee (emp_id,emp_name) values(0,'Neha Saini');
Step 4. When we execute the above query then you will get the following table.
Step 5. Now we will use the above table in the dropdown list using the following code.
Code
<head> <title>Dynamic Drop Down List</title> </head> <BODY bgcolor ="pink"> <form id="form1" name="form1" method="post" action=" echo $PHP_SELF; ?>"> Employee List :
<select Emp Name='NEW'> <option value="">--- Select ---</option> mysql_connect ("localhost","root","");
mysql_select_db ("company");
$select="company";
if (isset ($select)&&$select!=""){
$select=$_POST ['NEW'];
}
?> $list=mysql_query("select * from employee order by emp_id asc");
while($row_list=mysql_fetch_assoc($list)){
?> <option value=" echo $row_list['emp_id']; ?>" if($row_list['emp_id']==$select){ echo "selected"; } ?>>
echo $row_list['emp_name'];?>
</option> }
?> </select> <input type="submit" name="Submit" value="Select" /> </form> </body>
<head> <title>Dynamic Drop Down List</title> </head> <BODY bgcolor ="pink"> <form id="form1" name="form1" method="post" action=" echo $PHP_SELF; ?>"> Employee List :
<select Emp Name='NEW'> <option value="">--- Select ---</option> mysql_connect ("localhost","root","");
mysql_select_db ("company");
$select="company";
if (isset ($select)&&$select!=""){
$select=$_POST ['NEW'];
}
?> $list=mysql_query("select * from employee order by emp_id asc");
while($row_list=mysql_fetch_assoc($list)){
?> <option value=" echo $row_list['emp_id']; ?>" if($row_list['emp_id']==$select){ echo "selected"; } ?>>
echo $row_list['emp_name'];?>
</option> }
?> </select> <input type="submit" name="Submit" value="Select" /> </form> </body>
Output
Conclusion
So
in this article you saw how to create a static dropdown list and
dynamic dropdown list. Using this article one can easily understand how
to create static and dynamic dropdown lists in PHP
No comments:
Post a Comment