Outdated first php+mysql using AJAX technology of provincial and municipal 3-level linkage no Refresh menu source _php Tutorial

Source: Internet
Author: User
Absolutely original
Test Address: Http://www.mlmm.cn/mypage/?name=ceshi

Test page code:
Copy CodeThe code is as follows:



<title>Php+ajax Dynamic Build drop-down menu</title>







Regionss function Code:
QUOTE:
Copy CodeThe code is as follows://provincial Level 3 linkage drop-down menu function Regionss province. City.
function Regionss ($country = "People's Republic of China")
{
Global $db; $i = 1;
$text = " State/province \ n "; $result = $db->query ("Select Province from". Table_province. " WHERE country= ' $country ' ORDER by Provinceid '); while ($r = $db->fetch_array ($result)) {$text. = "". $r [' Province ']." "; $i + +; } $text. = "";
$text. = " City/County/district\ n ";
$text. = " County level\ n ";
return $text;

}
Regions.js's Code:



Copy CodeThe code is as follows://var ab = new Array ();
var xmlHttp;
var xmlhttpa;
function Createxmlhttprequest () {
if (window. ActiveXObject) {
XmlHttp = new ActiveXObject ("Microsoft.XMLHTTP");
}
else if (window. XMLHttpRequest) {
XmlHttp = new XMLHttpRequest ();
}
}
function Createxmlhttprequesta () {
if (window. ActiveXObject) {
XMLHTTPA = new ActiveXObject ("Microsoft.XMLHTTP");
}
else if (window. XMLHttpRequest) {
XMLHTTPA = new XMLHttpRequest ();
}
}

function Startrequest () {
Createxmlhttprequest ();
Createxmlhttprequesta ();
Xmlhttp.onreadystatechange = Handlestatechange;
Xmlhttpa.onreadystatechange = Handlestatechangearea;
document.getElementById (' Select2 '). options.length = 0;
document.getElementById (' Select3 '). options.length = 0;
var url = document.form1.select1.value;
var qurl = "/regions.php?province=" +url+ "&time=" +new Date (). GetTime ();
Xmlhttp.open ("GET", Qurl, True);
Xmlhttp.send (NULL);
SetTimeout ("Startrequest ()", 2000);
}

function Handlestatechange () {
if (xmlhttp.readystate = = 4) {
if (Xmlhttp.status = = 200) {
var obj = document.getElementById (' Select2 '); Writes the string returned by the server to a zone with ID select2 in the page
Obja = document.getElementById (' select3 '); Writes the string returned by the server to a zone with ID select3 in the page
eval (xmlhttp.responsetext);

}
}
}
function Handlestatechangearea () {
eval (xmlhttpa.responsetext);
}
var ab = new Array ();

function Startrequesta () {
Createxmlhttprequesta ();
Xmlhttpa.onreadystatechange = Handlestatechangea;
document.getElementById (' Select3 '). options.length = 0;
var url = document.form1.select2.value;
var qurl = "/regions.php?city=" +url+ "&time=" +new Date (). GetTime ();
Xmlhttpa.open ("GET", Qurl, True);
Xmlhttpa.send (NULL);
SetTimeout ("Startrequest ()", 2000);
}

function Handlestatechangea () {
if (xmlhttpa.readystate = = 4) {
if (Xmlhttpa.status = = 200) {
var obja = document.getElementById (' select3 ');
eval (xmlhttpa.responsetext);
Writes the string returned by the server to a zone with ID select3 in the page

}
}
}
Data Island regions.php page code



Copy CodeThe code is as follows: Require "common.php";
$city = $city? $city: "";
$area = $area? $area: "";
if ($province && $city = = ") {
Global $db; $i = 1;

$result = $db->query ("Select DISTINCT City from". Table_city. " WHERE province= ' $province ' ORDER by Cityid ');
while ($r = $db->fetch_array ($result))
{
$r [City]=iconv (' gb2312 ', ' UTF-8 ', $r [city]);
echo "obj.options[obj.options.length] = new Option ('". $r [City]. "', '". $r [City]. "'); \ n ";
$i + +;
}
$resultarea = $db->query ("Select DISTINCT City from". Table_city. " WHERE province= ' $province ' ORDER by Cityid ');
$r = $db->fetch_array ($resultarea);
$city = $r [City];
$resulta = $db->query ("Select DISTINCT area from". Table_city. " WHERE city= ' $city ' ORDER by Cityid ');
while ($ra = $db->fetch_array ($resulta))
{
$ra [Area]=iconv (' gb2312 ', ' UTF-8 ', $ra [area]);
echo "obja.options[obja.options.length] = new Option ('". $ra [Area]. "', '". $ra [Area]. "'); n ";
$i + +;
}


}
if ($city && $province = = ") {
Global $db; $i = 1;

$result = $db->query ("Select DISTINCT area from". Table_city. " WHERE city= ' $city ' ORDER by Cityid ');
while ($r = $db->fetch_array ($result))
{
$r [Area]=iconv (' gb2312 ', ' UTF-8 ', $r [area]);
echo "obja.options[obja.options.length] = new Option ('". $r [Area]. "', '". $r [Area]. "'); n ";
$i + +;
}
}
?>
Address Information Database:

I'm using a database from phpcms3.0, and I didn't make any changes.

This procedure can be used directly in phpcms3.0, if used in other places, please modify it yourself.

http://www.bkjia.com/PHPjc/317597.html www.bkjia.com true http://www.bkjia.com/PHPjc/317597.html techarticle Absolute Original test address: Http://www.mlmm.cn/mypage/?name=ceshi test page code: Copy code code as follows: HTML head metahttp-equiv= "Content-type" content= "Text/html;charset=gb2 ...

  • Related Article

    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.