大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
require 'city.php';
创新互联公司专注为客户提供全方位的互联网综合服务,包含不限于网站设计、成都网站建设、兰州网络推广、小程序设计、兰州网络营销、兰州企业策划、兰州品牌公关、搜索引擎seo、人物专访、企业宣传片、企业代运营等,从售前售中售后,我们都将竭诚为您服务,您的肯定,是我们最大的嘉奖;创新互联公司为所有大学生创业者提供兰州建站搭建服务,24小时服务热线:13518219792,官方网址:www.cdcxhl.com
// 连接数据库(PDO)
$pdo=new PDO('mysql:host=localhost;dbname=city','root','root');
$pdo-exec('set names utf8');
$pdo-setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE,PDO::FETCH_ASSOC);
// 实例化城市类
$c=new city();
$result=$c-mycity();
$city_id = 0;
foreach ($result as $k=$value) {
if(count($value) == count($value,1)){
$sql="insert into city_province (province) value ('{$value['province_name']}')";
$smt=$pdo-prepare($sql);
$smt-execute();
}else{
$sql11="insert into city_province (province) value ('{$value['province_name']}')";
$smt11=$pdo-prepare($sql11);
$smt11-execute();
foreach ($value['city'] as $v=$value1) {
$sql2="insert into city_name (name,province_id) values ('{$value1['city_name']}','{$k}')";
$smt2=$pdo-prepare($sql2);
$smt2-execute();
$city_id += 1;
echo $city_id.'br';
if(!empty($value1['area'])){
foreach ($value1['area'] as $valu1e2) {
$sql3="insert into city_area (area,city_id) values ('{$valu1e2}','{$city_id}')";
$smt3=$pdo-prepare($sql3);
$smt3-execute();
}
}
}
}
}
城市类太大了,发不了。
我是把省、市、地区分别存在三个数据表中(我是新手,刚自己写的)
?php return array (
1 =
array (
'province_name' = '北京市',
'city' =
array (
1 =
array (
'city_name' = '市辖区',
'area' =
array (
1 = '东城区',
2 = '西城区',
3 = '崇文区',
4 = '宣武区',
5 = '朝阳区',
6 = '丰台区',
7 = '石景山区',
8 = '海淀区',
9 = '门头沟区',
10 = '房山区',
11 = '通州区',
12 = '顺义区',
13 = '昌平区',
14 = '大兴区',
15 = '怀柔区',
16 = '平谷区',
),
),
2 =
array (
'city_name' = '北京周边',
'area' =
array (
1 = '密云县',
2 = '延庆县',
),
),
),
),
2 =
array (
'province_name' = '天津市',
'city' =
array (
1 =
array (
'city_name' = '市辖区',
'area' =
array (
1 = '和平区',
2 = '河东区',
3 = '河西区',
4 = '南开区',
5 = '河北区',
6 = '红桥区',
7 = '塘沽区',
8 = '汉沽区',
9 = '大港区',
10 = '东丽区',
11 = '西青区',
12 = '津南区',
13 = '北辰区',
14 = '武清区',
15 = '宝坻区',
),
),
2 =
array (
'city_name' = '天津周边',
'area' =
array (
1 = '宁河县',
2 = '静海县',
3 = '蓟 县',
),
),
),
),
3 =
array (
'province_name' = '河北省',
'city' =
array (
1 =
array (
'city_name' = '石家庄市',
'area' =
array (
1 = '长安区',
2 = '桥东区',
3 = '桥西区',
4 = '新华区',
5 = '井陉矿区',
6 = '裕华区',
7 = '井陉县',
8 = '正定县',
9 = '栾城县',
10 = '行唐县',
11 = '灵寿县',
12 = '高邑县',
13 = '深泽县',
14 = '赞皇县',
15 = '无极县',
16 = '平山县',
17 = '元氏县',
18 = '赵 县',
19 = '辛集市',
20 = '藁城市',
21 = '晋州市',
22 = '新乐市',
23 = '鹿泉市',
),
),
2 =
array (
'city_name' = '唐山市',
'area' =
array (
1 = '路南区',
2 = '路北区',
3 = '古冶区',
4 = '开平区',
5 = '丰南区',
6 = '丰润区',
7 = '滦 县',
8 = '滦南县',
9 = '乐亭县',
10 = '迁西县',
11 = '玉田县',
12 = '唐海县',
13 = '遵化市',
14 = '迁安市',
),
),
3 =
array (
'city_name' = '秦皇岛市',
'area' =
array (
1 = '海港区',
2 = '山海关区',
3 = '北戴河区',
4 = '青龙满族自治县',
5 = '昌黎县',
6 = '抚宁县',
7 = '卢龙县',
),
),
4 =
array (
'city_name' = '邯郸市',
'area' =
array (
1 = '邯山区',
2 = '丛台区',
3 = '复兴区',
4 = '峰峰矿区',
5 = '邯郸县',
6 = '临漳县',
7 = '成安县',
8 = '大名县',
9 = '涉 县',
10 = '磁 县',
11 = '肥乡县',
12 = '永年县',
13 = '邱 县',
14 = '鸡泽县',
15 = '广平县',
16 = '馆陶县',
17 = '魏 县',
18 = '曲周县',
19 = '武安市',
),
),
5 =
array (
'city_name' = '邢台市',
'area' =
array (
1 = '桥东区',
2 = '桥西区',
3 = '邢台县',
4 = '临城县',
需要使用到ajax。到网上查下,一堆。代码是固定的。
数据库设置
id,area,areaname
1 210000 辽宁省
2 210100 沈阳市
3 210104 大东区
select name='area1' id='area1' onchange="get_area2(this.value);"
这里读取省的数据
$sql="select area,areaname from area where right(area,4)='0000'";
/select
select name='area2' id='area2 'onchange="get_area(this.value);"
这里根据ajax读取数据,开始的时候是空的
/select
select name='area' id='area'
这里根据ajax读取数据,开始的时候是空的
/select
方法:
1,首先写get_area2 的js 代码,这里就用到ajax读取,这里获取的数据是区域代码的前两位代码(比如:21)
这个在根据这个21的参数,读取表中相关的市,
$sql="select area,areaname from area where left(area,2)='21' and right(area,2)='00'";
这个语句读取出来21的市代码
2,同一读取出来区的代码