php全国省市区数据库 省市数据库表下载
全国省市区查出来,怎么组装成三维数组,php的
首先,你要知道数据库是怎么保存的、
成都创新互联专注为客户提供全方位的互联网综合服务,包含不限于成都网站建设、成都做网站、寿光网络推广、小程序定制开发、寿光网络营销、寿光企业策划、寿光品牌公关、搜索引擎seo、人物专访、企业宣传片、企业代运营等,从售前售中售后,我们都将竭诚为您服务,您的肯定,是我们最大的嘉奖;成都创新互联为所有大学生创业者提供寿光建站搭建服务,24小时服务热线:18980820575,官方网址:www.cdcxhl.com
每个县肯定有一个市的父id,每个市都有一个省的父id,所以你查询卖段出来以后,根据父id就可以友配腊组装了,就类似这样
$arr = array(
'广东省'=array(
好滑 '深圳'=array(
'南山',
'福田'
),
'广州'=array(
'白云',
'沙河'
)
),
'福建省'=array(
............
)
);
请问怎么用PHP生成全国各省市的随时地址?
一般这样的都是存在数据库中,数据库3个字段 id pid name ,分别是 id 上级id 名称
用数组,三维数猛亮侍组
比如
id pid name
1 0 广东省
2 1 广枝吵州市
3 2 花都区
然后PHP读键兆取库,用一个迭代器,理论上可以取出无限级分类
php怎么写出全国的城市地区?
require 'city.php';
// 连接数据库(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怎么实现输出全国的省市区?
?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 = '临城县',
文章题目:php全国省市区数据库 省市数据库表下载
当前网址:http://cdiso.cn/article/ddpgepp.html