您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

最新县及县以上行政区划代码(截止2014年10月31日)

2024/3/27 12:54:06发布16次查看
采集自国家统计局
http://www.stats.gov.cn/tjsj/tjbz/xzqhdm/201504/t20150415_712722.html
有需要的同学自行下载附件,分割入库
文件格式如下
110000,北京市###110100,市辖区###110101,东城区###110102……
数据库方面create table `think_region` (
  `id` mediumint(6) unsigned not null default '0',
  `pid` mediumint(6) unsigned not null default '0',
  `name` varchar(100) not null default '',
  `type` tinyint(1) not null default '0',
  primary key (`id`),
  key `type` (`type`)
) engine=myisam default charset=utf8控制器方面        $db = m('region');
        $file = './code.txt';
        $content = file_get_contents($file);
        $content = think_s2a($content, '###');
        $i=0;$addall=array();
        foreach ($content as $v) {
            $data = think_s2a($v);
            switch (true) {
                case (preg_match('/\d{2}0000/', $data[0])):
                    $pid = 0;
                    $type = 0;
                    break;
                case (preg_match('/\d{4}00/', $data[0])):
                    $pid = substr($data[0], 0, 2) . '0000';
                    $type = 1;
                    break;
                default:
                    $pid = substr($data[0], 0, 4) . '00';
                    $type = 2;
            }
            $add = array(
                'id'   => $data[0],
                'pid'  => $pid,
                'name' => $data[1],
                'type' => $type,
            );
            $rules = array(
                array('id', 'require','id必须'),
                array('pid', 'require','pid必须'),
                array('name', 'require','neme必须'),
                array('type', array(0,1, 2), '类型范围', 1, 'in', 1),
                array('id', '', '该地区已录入', 1, 'unique', 1),
            );
            if ($db->validate($rules)->create($add, 1)) {
                $addall[$i]=$db->data();
                $i++;
            }
        }
        $db->addall($addall);
地区.zip ( 20.91 kb 下载:106 次 )
ad:真正免费,域名+虚机+企业邮箱=0元
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product