php+mysql+ajax+jquery省市地区四级联动,PHP+MYSQL+AJAX 3级联动下拉菜单

getcity.php页面:

require_once '../common.inc.php';//这边是我MYSQL数据的配置页面

$result=$_SG['db']->fetch_all("select * from area_district where parent_id=0");//这边是我MYSQL数据库的类(看不懂的写下面的注释里面的)

/*就是这样写的

*$conn=mysql_connect("localhost","root","");

*mysql_select_db("tt");

*mysql_query('Set names utf8');

*$sql="select * from area_district where parent_id='0'";

*$result=mysql_query($sql);

*/

foreach ($result as $key=>$val)

{

$str.=$val['area_name'].','.$val['area_id'].'|';

}

echo $str;

exit();

$str=substr($str,0,strlen($str)-1);

$result_str=explode('|',$str);

foreach($result_str as $key=>$val)

{

list($area_name,$area_code)=explode(',',$val);

echo "
";

echo $area_name;

echo "
";

}

?>

==========================================================================================

getdiqu.php页面:

require_once '../common.inc.php';//同理

$city=substr($_GET['city'],0,2);

$arry=array('31','11','12');//这边是选中MYSQL数据库中直辖市的parent_id 中的前2个字符,为了后面判断是否是直辖市

if(in_array($city,$arry)==true)//如果是直辖市

{

$i=$city."__00";

$sql="select area_name ,area_id from area_district where area_id like '$i' or parent_id like '$i'";

}

else//如果不是

{

$i=$city."__00";

$sql="select area_name ,area_id from area_district where area_id like '$i' and parent_id like '$i'";

}

$result=$_SG['db']->fetch_all($sql);//同理

foreach($result as $key=>$val){

$str.=$val['area_name'].','.$val['area_id'].'|';

}

echo $str;

?>

========================================================================================

zxs.php页面:

require_once '../common.inc.php';//同理

$diqu=substr($_GET['diqu'],0,4);

$arry=array('31','11','12');

if(in_array(substr($diqu,0,2),

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值