php怎么实现输出全国的省市区?
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php怎么实现输出全国的省市区?相关的知识,希望对你有一定的参考价值。
php怎么输出全国的省市区地址?
或者利用行政区划代码
http://www.stats.gov.cn/tjsj/tjbz/tjyqhdmhcxhfdm/2013/index.html
求代码,只有思路的别回复了!
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 => \'临城县\', 参考技术A <?php
$con = mysql_connect('localhost','root','');
if($con)
mysql_query('use city');
mysql_query('set names utf8');
else
echo "数据连接失败";
function myquery ($sql)
$res = mysql_query($sql);
return $res ? $res : false;
function getArray($sql)
$res = myquery($sql);
//var_dump($res);
if($res)
while($row = mysql_fetch_assoc($res))
$rows[] = $row;
return $rows ? $rows : null;
function getRow($sql)
$res = getArray($sql);
return $res[0] ? $res[0] : null;
function getOne($sql)
$res = myquery($sql);
if($res)
$num = mysql_num_rows($res);
return $num ? $num :0;
$sql = "select p.pid,p.pname,c.cid,c.cname,d.did,d.dname ";
$sql .= " from s_province as p left join s_city as c on p.pid = c.pid ";
$sql .= " left join s_district as d on d.cid = c.cid ";
$res = getArray($sql);
foreach($res as $val)
$list[$val['pid']] [] = $val;
var_dump($list);
应该可以输出你想要的内容。至于页面显示用html和css 和js就行了。这里就不介绍了
差一点就完美了,怎么去掉多余的代码啊?
追答没有多余的代码,都是封装的函数,你自己看着去掉就行了
本回答被提问者和网友采纳 参考技术B 多级联动…Mysql全国省市区以及邮编数据库
以上是关于php怎么实现输出全国的省市区?的主要内容,如果未能解决你的问题,请参考以下文章