After a while to move the Drop-down menu, share, hoping someone can continue to improve.

Source: Internet
Author: User
Menu | dropdown PHP Code:--------------------------------------------------------------------------------

<title>List</title>
<meta http-equiv= "Content-type" content= "text/html; charset=?????? " >
?
if (! ($link = mysql_connect ())) {
Fatal ("Could not connect to the local MySQL server.");
}

if (!mysql_select_db ("Loaction", $link))
{
Mysql_close ($link);
Fatal ("Could not select Database <b>parsersample</b>.");
}

$sql = "Select * from District ORDER by LocationID ASC";
$query =mysql_query ($sql, $link);
?>
<script language = "JavaScript" >

var Onecount;
Onecount = 0;
subcat = new Array ();
?
$count = 0;
while ($rs =mysql_fetch_array ($query)) {
?>
Subcat[<?= $count;? = = new Array ("<?= $rs [' districtname '];? > "," <?= $rs [' LocationID '];? > "," <?= $rs [' Districtid '];? > "," <?= $rs [' AreaCode ']?> ', ' <?= $rs [' ZipCode ']?> '];
?
$count + +;
}
?>
onecount=<?= $count?>;

function GetCode (Cityid) {
var Cityid=cityid;
var i;
For (I=0;i < Onecount; i++) {
if (subcat[i][2] = = Cityid) {
Document. FormData.AreaCode.value = subcat[i][3];
Document. FormData.ZipCode.value = subcat[i][4];
}
}
}

function Clearcode () {
Document. FormData.AreaCode.value = ';
Document. FormData.ZipCode.value = ';
}

function Getcity (LocationID)
{
Document. FormData.City.length = 0;

var Locationid=locationid;

var i;
Document. Formdata.city.options[0] = new Option (' = = the region of the selected city = = ', ');
For (I=0;i < onecount; i++)
{
if (subcat[i][1] = = LocationID)
{
Document. Formdata.city.options[document. FormData.City.length] = new Option (subcat[i][0], subcat[i][2]);
}
}

}
</script>
<body>
<form name= "FormData" method= "POST" action= "" >
Category: <select name= "Province" onchange= "Getcity" (document. Formdata.province.options[document. Formdata.province.selectedindex].value); Clearcode (); "size=" 1 ">
<option selected> Please select your province </option>
?
$sql 1= "SELECT * from Loaction";
$query =mysql_query ($sql 1, $link);
$a =mysql_num_rows ($query);
while ($rs 1=mysql_fetch_array ($query)) {
?>
<option value= "<?= $rs 1[' Loactionid '];? > "><?= $rs 1[' loactionname '];? ></option>
?? >
</select>
<select name= "City" onchange= "GetCode" (document. Formdata.city.options[document. Formdata.city.selectedindex].value); " >
<option selected Value= "" >== All areas ==</option>
</select>
<input type= "text" name= "AreaCode" ><input type= "text" name= "ZipCode" >
<input type= "Submit" >
</form>
</body>
?
if (!empty ($_post[' city ')) {
echo $_post[' city '];
}
?>


Table structure:

#
# The structure of the table ' district '
#
# Date Created: August 02, 2003 11:21
# Last modified: August 02, 2003 11:21
#

CREATE TABLE ' District ' (
' LocationID ' int (a) not NULL default ' 0 ',
' Districtid ' int (a) not NULL auto_increment,
' AreaCode ' varchar (4) Not NULL default ',
' ZipCode ' varchar (6) Not NULL default ',
' districtname ' varchar not NULL default ',
KEY ' Districtid ' (' Districtid ')
) Type=myisam auto_increment=7;

#
# table ' District ' data locationid--province id;districtid--City id;districtname--City, areacode--City, zipcode--, postal code
#

# --------------------------------------------------------

#
# The structure of the table ' Loaction '
#
# Date Created: August 02, 2003 09:28
# Last modified: August 02, 2003 10:36
#

CREATE TABLE ' loaction ' (
' Loactionid ' int (a) not NULL auto_increment,
' loactionname ' varchar not NULL default ',
KEY ' Loactionid ' (' Loactionid ')
) Type=myisam auto_increment=4;

#
# table ' loaction ' in data, loactionid--province id;loactionname--province name
#

#表


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.