|
Dynamic drop down menu/list box
|
|
|
|
|
Friday, 20 March 2009
|
|
HTML clipboard
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.
This tutorial require 1 PHP file and 1 table of mySQL database.
- dynamic_menu.php
- Database "tutorial" and table "name_list" with 2 fields: id(auto_increment),
name(varchar, 50) and put some records about 20 - 30 records into this table.
(directly by phpMyAdmin)
dynamic_menu.php
Source Code :
<?
mysql_connect("localhost","","");
mysql_select_db("tutorial");
if(isset($select)&&$select!=""){
$select=$_GET['select'];
}
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<form id="form1" name="form1" method="get" action="<? echo
$PHP_SELF; ?> ">
Car company :
<select name="select">
<option value="">--- Select ---</option>
<?
$list=mysql_query("select * from name_list order by id asc");
while($row_list=mysql_fetch_assoc($list)){
?>
<option value="<? echo $row_list['id']; ?>"
<? if($row_list['id']==$select){ echo "selected"; } ?>><?
echo $row_list['name']; ?></option>
<?
}
?>
</select>
<input type="submit" name="Submit" value="Select" />
</form>
<hr>
<p>
<?
if(isset($select)&&$select!=""){
$result=mysql_query("select * from name_list where id='$select'");
$row=mysql_fetch_assoc($result);
?>
Information about <strong><? echo $row['name']; ?></strong> company...</p>
<p>........................................<br>
........................................<br>
........................................
<?
}
mysql_close();
?>
</p>
</body>
</html>
|