jquery_ajax_+php_级联列表.doc

主页面 jilian.php

 

<?php

/*

 * Created on 2011-9-28

 *

 * To change the template for this generated file go to

 * Window - Preferences - PHPeclipse - PHP - Code Templates

 */

include_once("fun.php");

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title></title>

</head>

<script language="JavaScript" type="text/javascript" src="jquery-

1.4.2.js"></script>

<script>

              $(document).ready(function(){

                     $("#country").change(function(){

                            var cid = $("#country").val();

                     $.post("province.php",{id:cid},function(data){

                            //alert(data);

                            $("#province").html(data);

                            $("#city").html("<option value=\"0\">----请选择-

---</option>");

                            $("#county").html("<option value=\"0\">----请选择

----</option>");

                            $("#town").html("<option value=\"0\">----请选择-

---</option>");

                     });

                     });

                     $("#province").change(function(){

                            var pid = $("#province").val();

                     $.post("city.php",{id:pid},function(data){

                            //alert(data);

                            $("#city").html(data);

                            $("#county").html("<option value=\"0\">----请选择

----</option>");

                            $("#town").html("<option value=\"0\">----请选择-

---</option>");

                     });

                     });

                     $("#city").change(function(){

                            var cid = $("#city").val();

                     $.post("county.php",{id:cid},function(data){

                            //alert(data);

                            $("#county").html(data);

                            $("#town").html("<option value=\"0\">----请选择-

---</option>");

                     });

                     });

                     $("#county").change(function(){

                            var xid = $("#county").val();

                     $.post("town.php",{id:xid},function(data){

                            //alert(data);

                            $("#town").html(data);

                     });

                     });

              });

</script>

 

<body>

 

 <!-- <form action="test.php" method="post" > -->

国家

  <select name="country" id="country" >

    <option value="0">----请选择----</option>

    <?php

    $sql="select * from Country";

    $result = mysql_query($sql);

    while($rs = mysql_fetch_array($result)){

?>

       <option value="<?php echo $rs["cid"]; ?>"><?php echo $rs["country"]; ?

></option>

<?php

    }

    ?>

 

  </select>

省份

  <select name="province" id="province" >

    <option value="0">----请选择----</option>

  </select>

城市

<select name="city" id="city" >

    <option value="0">----请选择----</option>

  </select>

 县城

 <select name="county" id="county" >

    <option value="0">----请选择----</option>

  </select>

 城镇

 <select name="town" id="town" >

    <option value="0">----请选择----</option>

  </select>

<!-----

  <input type="submit" name="submit" value="提交"/>

</form>

---->

</body>

</html>

 

 

 

处理页面 province.php

 

 

<?php

/*

 * Created on 2011-9-28

 *

 * To change the template for this generated file go to

 * Window - Preferences - PHPeclipse - PHP - Code Templates

 */

 include_once("fun.php");

 $cid=$_POST["id"];

 //$cid = 1;

 $sql = "select * from Provinces where cid='".$cid."'";

 $res = mysql_query($sql);

 $arr8 = array();

 while($r = mysql_fetch_array($res)){

      $arr8[] = array($r["pid"],$r["province"]);

 }

//print_r($arr8);

       $str = "";

       $str .= "<option value=\"0\">----请选择----</option>";

       for($i=0;$i<count($arr8);$i++){

              $str .="<option value=\"{$arr8[$i][0]}\">{$arr8[$i][1]}

</option>";

       }

 

 

       echo $str;

 

?>

 

 

city.php

 

<?php

/*

 * Created on 2011-9-28

 *

 * To change the template for this generated file go to

 * Window - Preferences - PHPeclipse - PHP - Code Templates

 */

 include_once("fun.php");

 $pid=$_POST["id"];

 //$cid = 1;

 $sql = "select * from City where pid='".$pid."'";

 $res = mysql_query($sql);

 $arr8 = array();

 while($r = mysql_fetch_array($res)){

      $arr8[] = array($r["cid"],$r["city"]);

 }

//print_r($arr8);

       $str = "";

       $str .= "<option value=\"0\">----请选择----</option>";

       for($i=0;$i<count($arr8);$i++){

              $str .="<option value=\"{$arr8[$i][0]}\">{$arr8[$i][1]}

</option>";

       }

 

 

       echo $str;

 

?>

 

county.php

 

<?php

/*

 * Created on 2011-9-28

 *

 * To change the template for this generated file go to

 * Window - Preferences - PHPeclipse - PHP - Code Templates

 */

 include_once("fun.php");

 $cid=$_POST["id"];

 //$cid = 1;

 $sql = "select * from County where cid='".$cid."'";

 $res = mysql_query($sql);

 $arr8 = array();

 while($r = mysql_fetch_array($res)){

      $arr8[] = array($r["xid"],$r["county"]);

 }

//print_r($arr8);

       $str = "";

       $str .= "<option value=\"0\">----请选择----</option>";

       for($i=0;$i<count($arr8);$i++){

              $str .="<option value=\"{$arr8[$i][0]}\">{$arr8[$i][1]}

</option>";

       }

 

 

       echo $str;

 

?>

 

town.php

 

<?php

/*

 * Created on 2011-9-28

 *

 * To change the template for this generated file go to

 * Window - Preferences - PHPeclipse - PHP - Code Templates

 */

 include_once("fun.php");

 $xid=$_POST["id"];

 //$cid = 1;

 $sql = "select * from Town where xid='".$xid."'";

 $res = mysql_query($sql);

 $arr8 = array();

 while($r = mysql_fetch_array($res)){

      $arr8[] = array($r["tid"],$r["town"]);

 }

//print_r($arr8);

       $str = "";

       $str .= "<option value=\"0\">----请选择----</option>";

       for($i=0;$i<count($arr8);$i++){

              $str .="<option value=\"{$arr8[$i][0]}\">{$arr8[$i][1]}

</option>";

       }

 

 

       echo $str;

 

?>

 

数据库连接fun.php

<?php

/*

 * Created on 2011-9-28

 *

 * To change the template for this generated file go to

 * Window - Preferences - PHPeclipse - PHP - Code Templates

 */

  include_once("adodb/adodb.inc.php");

  mysql_connect("localhost", "root", "frotune123") or die("数据库连接失败!");

 mysql_select_db("COUNTRY");

 mysql_query("set names 'utf8' ");

?>

 

 

 

 

 

数据库:数据库名COUNTRY

 

 

/*

Navicat MySQL Data Transfer

 

Source Server         : 192.168.110.12_3306

Source Server Version : 50152

Source Host           : 192.168.110.12:3306

Source Database       : COUNTRY

 

Target Server Type    : MYSQL

Target Server Version : 50152

File Encoding         : 65001

 

Date: 2011-09-29 15:38:27

*/

 

SET FOREIGN_KEY_CHECKS=0;

-- ----------------------------

-- Table structure for `City`

-- ----------------------------

DROP TABLE IF EXISTS `City`;

CREATE TABLE `City` (

  `cid` int(2) NOT NULL AUTO_INCREMENT,

  `pid` int(2) NOT NULL,

  `city` varchar(20) NOT NULL,

  PRIMARY KEY (`cid`)

) ENGINE=MyISAM AUTO_INCREMENT=24 DEFAULT CHARSET=utf8;

 

-- ----------------------------

-- Records of City

-- ----------------------------

INSERT INTO City VALUES ('1', '1', '石家庄');

INSERT INTO City VALUES ('2', '1', '衡水');

INSERT INTO City VALUES ('3', '1', '保定');

INSERT INTO City VALUES ('4', '2', '郑州');

INSERT INTO City VALUES ('5', '2', '洛阳');

INSERT INTO City VALUES ('6', '2', '驻马店');

INSERT INTO City VALUES ('7', '3', '苏州');

INSERT INTO City VALUES ('8', '3', '宿迁');

INSERT INTO City VALUES ('9', '3', '南京');

INSERT INTO City VALUES ('10', '4', '长沙');

INSERT INTO City VALUES ('11', '4', '衡阳');

INSERT INTO City VALUES ('12', '4', '张家界');

INSERT INTO City VALUES ('13', '5', '亚拉巴马州');

INSERT INTO City VALUES ('14', '5', '阿拉斯加州');

INSERT INTO City VALUES ('15', '5', '亚利桑那州');

INSERT INTO City VALUES ('16', '6', '阿肯色州');

INSERT INTO City VALUES ('17', '6', '加利福尼亚州');

INSERT INTO City VALUES ('18', '6', '科罗拉多州');

INSERT INTO City VALUES ('19', '7', '特拉华州');

INSERT INTO City VALUES ('20', '7', '佛罗里达州');

INSERT INTO City VALUES ('21', '8', '温哥华');

INSERT INTO City VALUES ('22', '9', '埃德蒙顿市');

INSERT INTO City VALUES ('23', '10', '瑞吉娜');

 

-- ----------------------------

-- Table structure for `Country`

-- ----------------------------

DROP TABLE IF EXISTS `Country`;

CREATE TABLE `Country` (

  `cid` int(2) NOT NULL AUTO_INCREMENT,

  `country` varchar(20) DEFAULT NULL,

  PRIMARY KEY (`cid`)

) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;

 

-- ----------------------------

-- Records of Country

-- ----------------------------

INSERT INTO Country VALUES ('1', '中国');

INSERT INTO Country VALUES ('2', '美国');

INSERT INTO Country VALUES ('3', '加拿大');

 

-- ----------------------------

-- Table structure for `County`

-- ----------------------------

DROP TABLE IF EXISTS `County`;

CREATE TABLE `County` (

  `xid` int(2) NOT NULL AUTO_INCREMENT,

  `cid` int(2) NOT NULL,

  `county` varchar(20) NOT NULL,

  PRIMARY KEY (`xid`)

) ENGINE=MyISAM AUTO_INCREMENT=24 DEFAULT CHARSET=utf8;

 

-- ----------------------------

-- Records of County

-- ----------------------------

INSERT INTO County VALUES ('1', '1', '正定县');

INSERT INTO County VALUES ('2', '2', '景县');

INSERT INTO County VALUES ('3', '3', '保定的县');

INSERT INTO County VALUES ('4', '4', '郑州的县');

INSERT INTO County VALUES ('5', '5', '洛阳的县');

INSERT INTO County VALUES ('6', '6', '驻马店的县');

INSERT INTO County VALUES ('7', '7', '昆山');

INSERT INTO County VALUES ('8', '8', '宿迁的县');

INSERT INTO County VALUES ('9', '9', '南京的县');

INSERT INTO County VALUES ('10', '10', '长沙的县');

INSERT INTO County VALUES ('11', '11', '衡阳的县');

INSERT INTO County VALUES ('12', '12', '张家界的县');

INSERT INTO County VALUES ('13', '13', '亚拉巴马');

INSERT INTO County VALUES ('14', '14', '阿拉斯加');

INSERT INTO County VALUES ('15', '15', '亚利桑那');

INSERT INTO County VALUES ('16', '16', '阿肯色');

INSERT INTO County VALUES ('17', '17', '加利福尼亚');

INSERT INTO County VALUES ('18', '18', '科罗拉多');

INSERT INTO County VALUES ('19', '19', '特拉华');

INSERT INTO County VALUES ('20', '20', '佛罗里达的县');

INSERT INTO County VALUES ('21', '21', '温哥华的县');

INSERT INTO County VALUES ('22', '22', '埃德蒙顿');

INSERT INTO County VALUES ('23', '23', '瑞吉娜的县');

 

-- ----------------------------

-- Table structure for `Provinces`

-- ----------------------------

DROP TABLE IF EXISTS `Provinces`;

CREATE TABLE `Provinces` (

  `pid` int(2) NOT NULL AUTO_INCREMENT,

  `cid` int(2) NOT NULL,

  `province` varchar(20) NOT NULL,

  PRIMARY KEY (`pid`)

) ENGINE=MyISAM AUTO_INCREMENT=14 DEFAULT CHARSET=utf8;

 

-- ----------------------------

-- Records of Provinces

-- ----------------------------

INSERT INTO Provinces VALUES ('1', '1', '河北');

INSERT INTO Provinces VALUES ('2', '1', '河南');

INSERT INTO Provinces VALUES ('3', '1', '江苏');

INSERT INTO Provinces VALUES ('4', '1', '湖南');

INSERT INTO Provinces VALUES ('5', '2', '新英格兰地区');

INSERT INTO Provinces VALUES ('6', '2', '中央地区');

INSERT INTO Provinces VALUES ('7', '2', '中大西洋地区');

INSERT INTO Provinces VALUES ('8', '3', '不列颠哥伦比亚省');

INSERT INTO Provinces VALUES ('9', '3', '阿尔伯塔省');

INSERT INTO Provinces VALUES ('10', '3', '萨斯喀彻温省');

 

-- ----------------------------

-- Table structure for `Town`

-- ----------------------------

DROP TABLE IF EXISTS `Town`;

CREATE TABLE `Town` (

  `tid` int(2) NOT NULL AUTO_INCREMENT,

  `xid` int(2) NOT NULL,

  `town` varchar(20) NOT NULL,

  PRIMARY KEY (`tid`)

) ENGINE=MyISAM AUTO_INCREMENT=26 DEFAULT CHARSET=utf8;

 

-- ----------------------------

-- Records of Town

-- ----------------------------

INSERT INTO Town VALUES ('1', '1', '正定的镇');

INSERT INTO Town VALUES ('2', '2', '杜桥');

INSERT INTO Town VALUES ('3', '2', '龙华');

INSERT INTO Town VALUES ('4', '3', '保定的镇');

INSERT INTO Town VALUES ('5', '4', '郑州的镇');

INSERT INTO Town VALUES ('6', '5', '洛阳镇');

INSERT INTO Town VALUES ('7', '6', '驻马镇');

INSERT INTO Town VALUES ('8', '7', '花桥');

INSERT INTO Town VALUES ('9', '7', '陆家');

INSERT INTO Town VALUES ('10', '8', '宿迁的镇');

INSERT INTO Town VALUES ('11', '9', '南京的镇');

INSERT INTO Town VALUES ('12', '10', '长沙的镇');

INSERT INTO Town VALUES ('13', '11', '衡阳镇');

INSERT INTO Town VALUES ('14', '12', '张家界镇');

INSERT INTO Town VALUES ('15', '13', '亚拉巴马镇');

INSERT INTO Town VALUES ('16', '14', '阿拉斯加镇');

INSERT INTO Town VALUES ('17', '15', '亚利桑纳镇');

INSERT INTO Town VALUES ('18', '16', '阿肯色镇');

INSERT INTO Town VALUES ('19', '17', '加利福尼亚镇');

INSERT INTO Town VALUES ('20', '18', '科罗拉多镇');

INSERT INTO Town VALUES ('21', '19', '特拉华镇');

INSERT INTO Town VALUES ('22', '20', '佛罗里达镇');

INSERT INTO Town VALUES ('23', '21', '温哥华镇');

INSERT INTO Town VALUES ('24', '22', '埃德蒙顿镇');

INSERT INTO Town VALUES ('25', '23', '瑞吉娜镇');

 

 

 

 

效果图:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值