省市联动数据库
省市区三级联动菜单(附数据库)
省市区三级联动菜单(附数据库)<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><!----------------------------------------------------------------省的字段是:province--市的字段是:city--县的字段是:area---------------------------------------------------------------------------><mce:script type="text/javascript"><!--/*********定义创建XMLHttpRequest对象的⽅法***************************************/var xmlHttp;//声明变量var requestType="";//声明初始类型为空function createXMLHttpRequest()//定义创建⼀个跨浏览器函数的开头{if(window.ActiveXObject)//ActiveXObject对象到找到的时候返回的是真,否则是假{xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");//这个是使⽤IE的⽅法创建XmlHttp}else if(window.XMLHttpRequest){xmlHttp=new XMLHttpRequest();//这个是使⽤⾮IE的⽅法创建XmlHttp}}/****************判断服务器响应的事件,如果返回是4则说明交互完成,判断标⽰头,**************************************************/function handleStateChange(){//判断返回的⼀个函数,来确定执⾏那个的函数if(xmlHttp.readystate==4){//4说明是执⾏交互完毕0 (未初始化)1 (正在装载)2 (装载完毕) 3 (交互中)4 (完成)if(xmlHttp.status==200){//http的⼀个报头说明成功找到if(type=="city"){//判断查询的类型showcity();//返回响应的显⽰}else if(type="area"){//判断响应的查询的类型showarea();//返回响应的显⽰}}}}/**************************城市的⼀个查询函数**********************************************************/function queryCity(citycode){//执⾏程序查询,查询城市的createXMLHttpRequest();//调⽤创建XmlHttp的函数type="city";//表⽰类型,查询城市处理显⽰的时候需要⽤到var url='data.php?provincecode='+citycode+'&n='+Math.random();//设定URL传值⽅法同时防⽌缓存xmlHttp.open("GET",url,true);//建⽴服务器连接,异步传输treexmlHttp.onreadystatechange=handleStateChange;//处理这个响应所需要的函数xmlHttp.send(null);//执⾏程序函数这⾥的中间的参数是因为GET原因}/**********************县区的⼀个查询函数***********************************************************/function queryArea(citycode){//查询程序createXMLHttpRequest();//调⽤创建XmlHttp的函数type="area";//查询县的var url="data.php?citycode="+citycode+'&n='+Math.random();//设定URL传值⽅法同时防⽌缓存xmlHttp.open("GET",url,true);xmlHttp.onreadystatechange=handleStateChange;//处理响应的函数名xmlHttp.send(null);//执⾏程序函数这⾥的中间的参数是因为GET原因}/*********************⼀个显⽰函数**********************************************************/function showcity(){//显⽰函数document.getElementById("city").innerHTML=xmlHttp.responseText;//捕获ID显⽰返回的数据}function showarea(){document.getElementById("area").innerHTML=xmlHttp.responseText;//捕获ID显⽰返回的数据}$conn=mysql_connect("localhost","root","");//链接数据库mysql_select_db("novel");//选择数据库mysql_query("set names 'utf8'");//设定字符集$sql="select * from province";//查询数据库province表也就是省$result=mysql_query($sql);//执⾏语句赋值给变量><from id='form1'><!--输出表单头--><!--输出下拉列表框,并设定onchange响应事件,把省值传递过去--><select id='province' onchange='queryCity(this.options[this.selectedIndex].value)'><!--输出下拉列表项值--><option value='-1' selected>请选择省份</option><?phpwhile($row=mysql_fetch_row($result)){//循环循环查询显⽰省输出数据显⽰echo "<option value='$row[1]'>$row[2]</option>/n";}></select><!--下拉列表项尾数--><span id='city'></span><!--显⽰数据的城市的位置--><span id='area'></span><!--显⽰数据的城市的位置--></form><!--表单项结尾--></body></html><?php$provincecode=$_GET['provincecode'];//接收省键值$citycode=$_GET['citycode'];//接收城市键值$conn=mysql_connect("localhost","root","");//连接主机mysql_select_db("novel");//选择数据库mysql_query("set names 'utf8'");if($provincecode!=""){//如果传递过来的不为空则执⾏$sql="select * from city where provincecode=$provincecode";//查询城市符合属于上边传递过来的省的字段 $result=mysql_query($sql);//执⾏SQL查询语句print_r($row);><select onchange='queryArea(this.options[this.selectedIndex].value)'><!--下拉列表框开头--><option value='-1' selected>请选择城市</option><!--下拉列表框值开头--><?php while($row=mysql_fetch_row($result)){//循环记录集?><option value="<?= $row[1]?>"><?=$row[2]?></option><?php }?></select><?php }?><?phpif($citycode!=""){$sql="select * from area where citycode=$citycode";$result=mysql_query($sql);echo "<select>/n";echo "<option value='-1' selected>请选择县</option>/n";while($row=mysql_fetch_row($result)){echo "<option value='$row[1]'>$row[2]</option>/n";}echo "</select>/n";}>-- phpMyAdmin SQL Dump-- version 2.11.2-- ---- 主机: localhost-- ⽣成⽇期: 2008 年 07 ⽉ 11 ⽇ 00:45-- 服务器版本: 5.0.27-- PHP 版本: 5.2.0SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";---- 数据库: `novel`--CREATE DATABASE `novel` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;USE `novel`;-- 表的结构 `area`--CREATE TABLE IF NOT EXISTS `area` (`id` int(11) NOT NULL auto_increment,`code` varchar(6) NOT NULL,`name` varchar(20) NOT NULL,`citycode` varchar(6) NOT NULL,PRIMARY KEY (`id`)) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=3145 ; ---- 导出表中的数据 `area`--INSERT INTO `area` (`id`, `code`, `name`, `citycode`) VALUES(1, '110101', '东城区', '110100'),(2, '110102', '西城区', '110100'),(3, '110103', '崇⽂区', '110100'),(4, '110104', '宣武区', '110100'),(5, '110105', '朝阳区', '110100'),(6, '110106', '丰台区', '110100'),(7, '110107', '⽯景⼭区', '110100'),(8, '110108', '海淀区', '110100'),(9, '110109', '门头沟区', '110100'),(10, '110111', '房⼭区', '110100'),(11, '110112', '通州区', '110100'),(12, '110113', '顺义区', '110100'),(13, '110114', '昌平区', '110100'),(14, '110115', '⼤兴区', '110100'),(15, '110116', '怀柔区', '110100'),(16, '110117', '平⾕区', '110100'),(17, '110228', '密云县', '110200'),(18, '110229', '延庆县', '110200'),(19, '120101', '和平区', '120100'),(20, '120102', '河东区', '120100'),(21, '120103', '河西区', '120100'),(22, '120104', '南开区', '120100'),(23, '120105', '河北区', '120100'),(24, '120106', '红桥区', '120100'),(25, '120107', '塘沽区', '120100'),(26, '120108', '汉沽区', '120100'),(27, '120109', '⼤港区', '120100'),(28, '120110', '东丽区', '120100'),(29, '120111', '西青区', '120100'),(30, '120112', '津南区', '120100'),(31, '120113', '北⾠区', '120100'),(32, '120114', '武清区', '120100'),(33, '120115', '宝坻区', '120100'),(34, '120221', '宁河县', '120200'),(35, '120223', '静海县', '120200'),(36, '120225', '蓟 县', '120200'),(37, '130101', '市辖区', '130100'),(38, '130102', '长安区', '130100'),(39, '130103', '桥东区', '130100'),(40, '130104', '桥西区', '130100'),(41, '130105', '新华区', '130100'),(42, '130107', '井陉矿区', '130100'),(43, '130108', '裕华区', '130100'),(44, '130121', '井陉县', '130100'),(45, '130123', '正定县', '130100'),(46, '130124', '栾城县', '130100'),(47, '130125', '⾏唐县', '130100'),(48, '130126', '灵寿县', '130100'),(49, '130127', '⾼⾢县', '130100'),(50, '130128', '深泽县', '130100'),(51, '130129', '赞皇县', '130100'),(52, '130130', '⽆极县', '130100'),(53, '130131', '平⼭县', '130100'),(54, '130132', '元⽒县', '130100'),(55, '130133', '赵 县', '130100'),(56, '130181', '⾟集市', '130100'),(57, '130182', '藁城市', '130100'),(58, '130183', '晋州市', '130100'),(59, '130184', '新乐市', '130100'),(60, '130185', '⿅泉市', '130100'),(61, '130201', '市辖区', '130200'),(62, '130202', '路南区', '130200'),(63, '130203', '路北区', '130200'),(64, '130204', '古冶区', '130200'),(73, '130230', '唐海县', '130200'), (74, '130281', '遵化市', '130200'), (75, '130283', '迁安市', '130200'), (76, '130301', '市辖区', '130300'), (77, '130302', '海港区', '130300'), (78, '130303', '⼭海关区', '130300'), (79, '130304', '北戴河区', '130300'), (80, '130321', '青龙满族⾃治县', '130300'), (81, '130322', '昌黎县', '130300'), (82, '130323', '抚宁县', '130300'), (83, '130324', '卢龙县', '130300'), (84, '130401', '市辖区', '130400'), (85, '130402', '邯⼭区', '130400'), (86, '130403', '丛台区', '130400'), (87, '130404', '复兴区', '130400'), (88, '130406', '峰峰矿区', '130400'), (89, '130421', '邯郸县', '130400'), (90, '130423', '临漳县', '130400'), (91, '130424', '成安县', '130400'), (92, '130425', '⼤名县', '130400'), (93, '130426', '涉 县', '130400'), (94, '130427', '磁 县', '130400'), (95, '130428', '肥乡县', '130400'), (96, '130429', '永年县', '130400'), (97, '130430', '邱 县', '130400'), (98, '130431', '鸡泽县', '130400'), (99, '130432', '⼴平县', '130400'), (100, '130433', '馆陶县', '130400'), (101, '130434', '魏 县', '130400'), (102, '130435', '曲周县', '130400'), (103, '130481', '武安市', '130400'), (104, '130501', '市辖区', '130500'), (105, '130502', '桥东区', '130500'), (106, '130503', '桥西区', '130500'), (107, '130521', '邢台县', '130500'), (108, '130522', '临城县', '130500'), (109, '130523', '内丘县', '130500'), (110, '130524', '柏乡县', '130500'), (111, '130525', '隆尧县', '130500'), (112, '130526', '任 县', '130500'), (113, '130527', '南和县', '130500'), (114, '130528', '宁晋县', '130500'), (115, '130529', '巨⿅县', '130500'), (116, '130530', '新河县', '130500'), (117, '130531', '⼴宗县', '130500'), (118, '130532', '平乡县', '130500'), (119, '130533', '威 县', '130500'), (120, '130534', '清河县', '130500'), (121, '130535', '临西县', '130500'), (122, '130581', '南宫市', '130500'), (123, '130582', '沙河市', '130500'), (124, '130601', '市辖区', '130600'), (125, '130602', '新市区', '130600'), (126, '130603', '北市区', '130600'), (127, '130604', '南市区', '130600'), (128, '130621', '满城县', '130600'), (129, '130622', '清苑县', '130600'), (130, '130623', '涞⽔县', '130600'), (131, '130624', '⾩平县', '130600'), (132, '130625', '徐⽔县', '130600'), (133, '130626', '定兴县', '130600'), (134, '130627', '唐 县', '130600'), (135, '130628', '⾼阳县', '130600'), (136, '130629', '容城县', '130600'), (137, '130630', '涞源县', '130600'), (138, '130631', '望都县', '130600'), (139, '130632', '安新县', '130600'), (140, '130633', '易 县', '130600'), (141, '130634', '曲阳县', '130600'), (142, '130635', '蠡 县', '130600'), (143, '130636', '顺平县', '130600'), (144, '130637', '博野县', '130600'), (145, '130638', '雄 县', '130600'), (146, '130681', '涿州市', '130600'), (147, '130682', '定州市', '130600'), (148, '130683', '安国市', '130600'),(157, '130723', '康保县', '130700'),(158, '130724', '沽源县', '130700'),(159, '130725', '尚义县', '130700'),(160, '130726', '蔚 县', '130700'),(161, '130727', '阳原县', '130700'),(162, '130728', '怀安县', '130700'),(163, '130729', '万全县', '130700'),(164, '130730', '怀来县', '130700'),(165, '130731', '涿⿅县', '130700'),(166, '130732', '⾚城县', '130700'),(167, '130733', '崇礼县', '130700'),(168, '130801', '市辖区', '130800'),(169, '130802', '双桥区', '130800'),(170, '130803', '双滦区', '130800'),(171, '130804', '鹰⼿营⼦矿区', '130800'), (172, '130821', '承德县', '130800'),(173, '130822', '兴隆县', '130800'),(174, '130823', '平泉县', '130800'),(175, '130824', '滦平县', '130800'),(176, '130825', '隆化县', '130800'),(177, '130826', '丰宁满族⾃治县', '130800'), (178, '130827', '宽城满族⾃治县', '130800'), (179, '130828', '围场满族蒙古族⾃治县', '130800'), (180, '130901', '市辖区', '130900'),(181, '130902', '新华区', '130900'),(182, '130903', '运河区', '130900'),(183, '130921', '沧 县', '130900'),(184, '130922', '青 县', '130900'),(185, '130923', '东光县', '130900'),(186, '130924', '海兴县', '130900'),(187, '130925', '盐⼭县', '130900'),(188, '130926', '肃宁县', '130900'),(189, '130927', '南⽪县', '130900'),(190, '130928', '吴桥县', '130900'),(191, '130929', '献 县', '130900'),(192, '130930', '孟村回族⾃治县', '130900'), (193, '130981', '泊头市', '130900'),(194, '130982', '任丘市', '130900'),(195, '130983', '黄骅市', '130900'),(196, '130984', '河间市', '130900'),(197, '131001', '市辖区', '131000'),(198, '131002', '安次区', '131000'),(199, '131003', '⼴阳区', '131000'),(200, '131022', '固安县', '131000'),(201, '131023', '永清县', '131000'),(202, '131024', '⾹河县', '131000'),(203, '131025', '⼤城县', '131000'),(204, '131026', '⽂安县', '131000'),(205, '131028', '⼤⼚回族⾃治县', '131000'), (206, '131081', '霸州市', '131000'),(207, '131082', '三河市', '131000'),(208, '131101', '市辖区', '131100'),(209, '131102', '桃城区', '131100'),(210, '131121', '枣强县', '131100'),(211, '131122', '武⾢县', '131100'),(212, '131123', '武强县', '131100'),(213, '131124', '饶阳县', '131100'),(214, '131125', '安平县', '131100'),(215, '131126', '故城县', '131100'),(216, '131127', '景 县', '131100'),(217, '131128', '⾩城县', '131100'),(218, '131181', '冀州市', '131100'),(219, '131182', '深州市', '131100'),(220, '140101', '市辖区', '140100'),(221, '140105', '⼩店区', '140100'),(222, '140106', '迎泽区', '140100'),(223, '140107', '杏花岭区', '140100'),(224, '140108', '尖草坪区', '140100'),(225, '140109', '万柏林区', '140100'),(226, '140110', '晋源区', '140100'),(227, '140121', '清徐县', '140100'),(228, '140122', '阳曲县', '140100'),(229, '140123', '娄烦县', '140100'),(230, '140181', '古交市', '140100'),(231, '140201', '市辖区', '140200'),(232, '140202', '城 区', '140200'),(241, '140226', '左云县', '140200'), (242, '140227', '⼤同县', '140200'), (243, '140301', '市辖区', '140300'), (244, '140302', '城 区', '140300'), (245, '140303', '矿 区', '140300'), (246, '140311', '郊 区', '140300'), (247, '140321', '平定县', '140300'), (248, '140322', '盂 县', '140300'), (249, '140401', '市辖区', '140400'), (250, '140402', '城 区', '140400'), (251, '140411', '郊 区', '140400'), (252, '140421', '长治县', '140400'), (253, '140423', '襄垣县', '140400'), (254, '140424', '屯留县', '140400'), (255, '140425', '平顺县', '140400'), (256, '140426', '黎城县', '140400'), (257, '140427', '壶关县', '140400'), (258, '140428', '长⼦县', '140400'), (259, '140429', '武乡县', '140400'), (260, '140430', '沁 县', '140400'), (261, '140431', '沁源县', '140400'), (262, '140481', '潞城市', '140400'), (263, '140501', '市辖区', '140500'), (264, '140502', '城 区', '140500'), (265, '140521', '沁⽔县', '140500'), (266, '140522', '阳城县', '140500'), (267, '140524', '陵川县', '140500'), (268, '140525', '泽州县', '140500'), (269, '140581', '⾼平市', '140500'), (270, '140601', '市辖区', '140600'), (271, '140602', '朔城区', '140600'), (272, '140603', '平鲁区', '140600'), (273, '140621', '⼭阴县', '140600'), (274, '140622', '应 县', '140600'), (275, '140623', '右⽟县', '140600'), (276, '140624', '怀仁县', '140600'), (277, '140701', '市辖区', '140700'), (278, '140702', '榆次区', '140700'), (279, '140721', '榆社县', '140700'), (280, '140722', '左权县', '140700'), (281, '140723', '和顺县', '140700'), (282, '140724', '昔阳县', '140700'), (283, '140725', '寿阳县', '140700'), (284, '140726', '太⾕县', '140700'), (285, '140727', '祁 县', '140700'), (286, '140728', '平遥县', '140700'), (287, '140729', '灵⽯县', '140700'), (288, '140781', '介休市', '140700'), (289, '140801', '市辖区', '140800'), (290, '140802', '盐湖区', '140800'), (291, '140821', '临猗县', '140800'), (292, '140822', '万荣县', '140800'), (293, '140823', '闻喜县', '140800'), (294, '140824', '稷⼭县', '140800'), (295, '140825', '新绛县', '140800'), (296, '140826', '绛 县', '140800'), (297, '140827', '垣曲县', '140800'), (298, '140828', '夏 县', '140800'), (299, '140829', '平陆县', '140800'), (300, '140830', '芮城县', '140800'), (301, '140881', '永济市', '140800'), (302, '140882', '河津市', '140800'), (303, '140901', '市辖区', '140900'), (304, '140902', '忻府区', '140900'), (305, '140921', '定襄县', '140900'), (306, '140922', '五台县', '140900'), (307, '140923', '代 县', '140900'), (308, '140924', '繁峙县', '140900'), (309, '140925', '宁武县', '140900'), (310, '140926', '静乐县', '140900'), (311, '140927', '神池县', '140900'), (312, '140928', '五寨县', '140900'), (313, '140929', '岢岚县', '140900'), (314, '140930', '河曲县', '140900'), (315, '140931', '保德县', '140900'), (316, '140932', '偏关县', '140900'),(325, '141026', '安泽县', '141000'),(326, '141027', '浮⼭县', '141000'),(327, '141028', '吉 县', '141000'),(328, '141029', '乡宁县', '141000'),(329, '141030', '⼤宁县', '141000'),(330, '141031', '隰 县', '141000'),(331, '141032', '永和县', '141000'),(332, '141033', '蒲 县', '141000'),(333, '141034', '汾西县', '141000'),(334, '141081', '侯马市', '141000'),(335, '141082', '霍州市', '141000'),(336, '141101', '市辖区', '141100'),(337, '141102', '离⽯区', '141100'),(338, '141121', '⽂⽔县', '141100'),(339, '141122', '交城县', '141100'),(340, '141123', '兴 县', '141100'),(341, '141124', '临 县', '141100'),(342, '141125', '柳林县', '141100'),(343, '141126', '⽯楼县', '141100'),(344, '141127', '岚 县', '141100'),(345, '141128', '⽅⼭县', '141100'),(346, '141129', '中阳县', '141100'),(347, '141130', '交⼝县', '141100'),(348, '141181', '孝义市', '141100'),(349, '141182', '汾阳市', '141100'),(350, '150101', '市辖区', '150100'),(351, '150102', '新城区', '150100'),(352, '150103', '回民区', '150100'),(353, '150104', '⽟泉区', '150100'),(354, '150105', '赛罕区', '150100'),(355, '150121', '⼟默特左旗', '150100'), (356, '150122', '托克托县', '150100'),(357, '150123', '和林格尔县', '150100'), (358, '150124', '清⽔河县', '150100'),(359, '150125', '武川县', '150100'),(360, '150201', '市辖区', '150200'),(361, '150202', '东河区', '150200'),(362, '150203', '昆都仑区', '150200'),(363, '150204', '青⼭区', '150200'),(364, '150205', '⽯拐区', '150200'),(365, '150206', '⽩云矿区', '150200'),(366, '150207', '九原区', '150200'),(367, '150221', '⼟默特右旗', '150200'), (368, '150222', '固阳县', '150200'),(369, '150223', '达尔罕茂明安联合旗', '150200'), (370, '150301', '市辖区', '150300'),(371, '150302', '海勃湾区', '150300'),(372, '150303', '海南区', '150300'),(373, '150304', '乌达区', '150300'),(374, '150401', '市辖区', '150400'),(375, '150402', '红⼭区', '150400'),(376, '150403', '元宝⼭区', '150400'),(377, '150404', '松⼭区', '150400'),(378, '150421', '阿鲁科尔沁旗', '150400'), (379, '150422', '巴林左旗', '150400'),(380, '150423', '巴林右旗', '150400'),(381, '150424', '林西县', '150400'),(382, '150425', '克什克腾旗', '150400'), (383, '150426', '翁⽜特旗', '150400'),(384, '150428', '喀喇沁旗', '150400'),(385, '150429', '宁城县', '150400'),(386, '150430', '敖汉旗', '150400'),(387, '150501', '市辖区', '150500'),(388, '150502', '科尔沁区', '150500'),(389, '150521', '科尔沁左翼中旗', '150500'), (390, '150522', '科尔沁左翼后旗', '150500'), (391, '150523', '开鲁县', '150500'),(392, '150524', '库伦旗', '150500'),(393, '150525', '奈曼旗', '150500'),(394, '150526', '扎鲁特旗', '150500'),(395, '150581', '霍林郭勒市', '150500'), (396, '150602', '东胜区', '150600'),(397, '150621', '达拉特旗', '150600'),(398, '150622', '准格尔旗', '150600'),(399, '150623', '鄂托克前旗', '150600'), (400, '150624', '鄂托克旗', '150600'),(407, '150722', '莫⼒达⽡达斡尔族⾃治旗', '150700'), (408, '150723', '鄂伦春⾃治旗', '150700'),(409, '150724', '鄂温克族⾃治旗', '150700'), (410, '150725', '陈巴尔虎旗', '150700'),(411, '150726', '新巴尔虎左旗', '150700'),(412, '150727', '新巴尔虎右旗', '150700'),(413, '150781', '满洲⾥市', '150700'),(414, '150782', '⽛克⽯市', '150700'),(415, '150783', '扎兰屯市', '150700'),(416, '150784', '额尔古纳市', '150700'),(417, '150785', '根河市', '150700'),(418, '150801', '市辖区', '150800'),(419, '150802', '临河区', '150800'),(420, '150821', '五原县', '150800'),(421, '150822', '磴⼝县', '150800'),(422, '150823', '乌拉特前旗', '150800'),(423, '150824', '乌拉特中旗', '150800'),(424, '150825', '乌拉特后旗', '150800'),(425, '150826', '杭锦后旗', '150800'),(426, '150901', '市辖区', '150900'),(427, '150902', '集宁区', '150900'),(428, '150921', '卓资县', '150900'),(429, '150922', '化德县', '150900'),(430, '150923', '商都县', '150900'),(431, '150924', '兴和县', '150900'),(432, '150925', '凉城县', '150900'),(433, '150926', '察哈尔右翼前旗', '150900'), (434, '150927', '察哈尔右翼中旗', '150900'), (435, '150928', '察哈尔右翼后旗', '150900'), (436, '150929', '四⼦王旗', '150900'),(437, '150981', '丰镇市', '150900'),(438, '152201', '乌兰浩特市', '152200'),(439, '152202', '阿尔⼭市', '152200'),(440, '152221', '科尔沁右翼前旗', '152200'), (441, '152222', '科尔沁右翼中旗', '152200'), (442, '152223', '扎赉特旗', '152200'),(443, '152224', '突泉县', '152200'),(444, '152501', '⼆连浩特市', '152500'),(445, '152502', '锡林浩特市', '152500'),(446, '152522', '阿巴嘎旗', '152500'),(447, '152523', '苏尼特左旗', '152500'),(448, '152524', '苏尼特右旗', '152500'),(449, '152525', '东乌珠穆沁旗', '152500'),(450, '152526', '西乌珠穆沁旗', '152500'),(451, '152527', '太仆寺旗', '152500'),(452, '152528', '镶黄旗', '152500'),(453, '152529', '正镶⽩旗', '152500'),(454, '152530', '正蓝旗', '152500'),(455, '152531', '多伦县', '152500'),(456, '152921', '阿拉善左旗', '152900'),(457, '152922', '阿拉善右旗', '152900'),(458, '152923', '额济纳旗', '152900'),(459, '210101', '市辖区', '210100'),(460, '210102', '和平区', '210100'),(461, '210103', '沈河区', '210100'),(462, '210104', '⼤东区', '210100'),(463, '210105', '皇姑区', '210100'),(464, '210106', '铁西区', '210100'),(465, '210111', '苏家屯区', '210100'),(466, '210112', '东陵区', '210100'),(467, '210113', '新城⼦区', '210100'),(468, '210114', '于洪区', '210100'),(469, '210122', '辽中县', '210100'),(470, '210123', '康平县', '210100'),(471, '210124', '法库县', '210100'),(472, '210181', '新民市', '210100'),(473, '210201', '市辖区', '210200'),(474, '210202', '中⼭区', '210200'),(475, '210203', '西岗区', '210200'),(476, '210204', '沙河⼝区', '210200'),(477, '210211', '⽢井⼦区', '210200'),(478, '210212', '旅顺⼝区', '210200'),(479, '210213', '⾦州区', '210200'),(480, '210224', '长海县', '210200'),(481, '210281', '⽡房店市', '210200'),(482, '210282', '普兰店市', '210200'),(483, '210283', '庄河市', '210200'),(484, '210301', '市辖区', '210300'),。
省市二级联动数据库生成代码(JAVA)
省市二级联动数据库生成代码(JAVA)来源:开发界数据来源于谷歌地图省市列表(无省、市、区字样)省市列表(带省、市、区)源代码注意:由于我不想把省、市、区这样的字也转换成拼音,如河北省转换为HBS,北京市转换为BJS,我把省、市、区相关字样已删除,但我也保留了原文件,有需要的可以下载。
表结构:[sql] view plaincopyprint?CREATE TABLE IF NOT EXISTS `city` (`id` varchar(50) NOT NULL,`type` varchar(50) NOT NULL,`parent_id` varchar(50) NOT NULL,`name` varchar(50) NOT NULL,`short` varchar(50) NOT NULL,PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;CREATE TABLE IF NOT EXISTS `city` (`id` varchar(50) NOT NULL,`type` varchar(50) NOT NULL,`parent_id` varchar(50) NOT NULL,`name` varchar(50) NOT NULL,`short` varchar(50) NOT NULL,PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;具体实现请看以下代码:[java] view plaincopyprint?package com.zxq.pinyin;import java.io.BufferedReader;import java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.IOException;import java.io.InputStreamReader;import java.util.ArrayList;import java.util.Iterator;import java.util.LinkedHashMap;import java.util.List;import java.util.Map;import java.util.Map.Entry;import java.util.Set;import net.sourceforge.pinyin4j.PinyinHelper;import net.sourceforge.pinyin4j.format.HanyuPinyinCaseType;import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;import net.sourceforge.pinyin4j.format.HanyuPinyinToneType;import net.sourceforge.pinyin4j.format.HanyuPinyinVCharType;import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination;public class Covert {/*** 汉字转拼音,并将结果保存到省或市的map中* @param words 需要转换的字符串* @param provinceOrCity 省或市的Map*/public static void wordToPinYinSZM(String words, Map<String, String> provinceOrCity) { //调用Pinyin4J的方法//定义拼音输出格式HanyuPinyinOutputFormat hof = new HanyuPinyinOutputFormat();//大写hof.setCaseType(HanyuPinyinCaseType.UPPERCASE);//不包含声调hof.setToneType(HanyuPinyinToneType.WITHOUT_TONE);//u用V表示hof.setVCharType(HanyuPinyinVCharType.WITH_V);//由于只能对单字转换,所以需要把字符串转换为字符数组char[] characters = words.toCharArray();try {//StringBuilder存放结果StringBuilder sb = new StringBuilder();for(int i = 0; i < characters.length; i++) {//调用汉字转拼音核心方法,大家可以看到返回的是一个数组,因为有的汉字有多音字,所以可能返回多个//拼音结果,对此,我只取第一个,pinyinArray[0],这样做不好的地方就是可能有的简拼不准确,例如//“重庆”我得到的是ZQ,zhong qing,这一点有待完善String[] pinyinArray = PinyinHelper.toHanyuPinyinStringArray(characters[i], hof);//substring(0, 1)则表示只取首字母sb.append(pinyinArray[0].substring(0, 1));}//放入省或市的Map中provinceOrCity.put(words, sb.toString());} catch (BadHanyuPinyinOutputFormatCombination e) {e.printStackTrace();}}/*** @param args*/public static void main(String[] args) {//读取事先定义好的省市文本文件,第一行为省/直辖市,第二行为各地级市File provinceFile = new File("F:\\province_city\\province.txt");//定义保存省、市数据的数据结构。
省市区三级联动数据库代码(国家统计局最新代码、包含整理步骤)
省市区三级联动数据库代码(国家统计局最新代码、包含整理步骤)最终整理后的成果图。
最近项⽬要⽤到省市区地址三级联动。
原有的数据是⽼版本的。
在⽹上找了找,发现很多,也很杂。
最终决定⾃⼰整理⼀份,就当练⼿了。
看到的数据只有代码和名称两列数据如:110000 北京市110100 市辖区110101 东城区去空格整理后复制到excel 表中供导⼊数据库1、⾸先要把地址分出 1 、2 、3 级代表省、市、区。
那么问题来了。
原先想依据名称列的缩进来进⾏区分,但是想想有点复杂,⽽且容易出错。
后来⽤地区的编码规律来区分编码为 6 个字符组成例如:110101⾸先把表结构建起来吧。
从Excel表导⼊数据吧,这个就不说咯现在开始了!如果后4位为"0000" ---------------------是省级 1UPDATE[region]SET level=1WHERE SUBSTRING(code,3,6) ='0000'GO如果后2位为"00" 和等级level 不等于1----------是市级 2UPDATE[Test].[dbo].[region]SET[level]=2WHERE SUBSTRING(code,5,6) ='00'and ([level]<>1 ro [level] is null)GO备注:什么?执⾏了没效果?先把 level 字段赋值为 0 吧。
UPDATE [region]SET level = 0WHERE level is nullGO其他的 -----------------------------------是区级 3UPDATE[region]SET level=3WHERE level = 0GO2、现在我们来把⽗ID 整理出来也是依靠地址编码看代码就懂了啦省级UPDATE[region]SET parent_id =0WHERE level=1GO市级UPDATE aSET a.[parent_id]= b.[id]from[region] a,[region] bWHERE SUBSTRING(a.[code],1,2) =SUBSTRING(b.[code],1,2) and a.[level]=2and b.[level]=1GO区级UPDATE aSET a.[parent_id]= b.[id]from[region] a,[region] bWHERE SUBSTRING(a.[code],1,4) =SUBSTRING(b.[code],1,4) and a.[level]=3and b.[level]=2GO3、整理地区全称(这个字段有必要整理出来,原因嘛,选择联动地区获得省市区地址名称的时候会有意外的惊喜!例如:北京市市辖区XXX区,北京市县XXX县虽然没错但是影响美观)直接上代码:UPDATE[region]SET text_full =textWHERE id = id and level=1GOUPDATE aSET a.text_full = b.text_full + a.text from[region] a,[region] bWHERE a.parent_id = b.id and a.[level]=2and b.[level]=1GOUPDATE aSET a.text_full = b.text_full + a.text_full from[region] a,[region] bWHERE a.parent_id = b.id and a.[level]=3and b.[level]=2GO现在好了,看下检查下数据。
省市县三级联动的SQL语句
这篇文章主要介绍了省市县三级联动的SQL语句,包括建表及插入数据,需要的朋友可以参考下首先是建表语句代码如下:CREATE TABLE `t_address_province` (`id` INT AUTO_INCREMENT PRIMARY KEY COMMENT '主键',`code` CHAR(6) NOT NULL COMMENT '省份编码',`name` VARCHAR(40) NOT NULL COMMENT '省份名称') ENGINE=InnoDB DEFAULT CHARSET=UTF8 COMMENT='省份信息表';CREATE TABLE `t_address_city` (`id` INT AUTO_INCREMENT PRIMARY KEY COMMENT '主键',`code` CHAR(6) NOT NULL COMMENT '城市编码',`name` VARCHAR(40) NOT NULL COMMENT '城市名称',`provinceCode` CHAR(6) NOT NULL COMMENT '所属省份编码') ENGINE=InnoDB DEFAULT CHARSET=UTF8 COMMENT='城市信息表';CREATE TABLE `t_address_town` (`id` INT AUTO_INCREMENT PRIMARY KEY COMMENT '主键',`code` CHAR(6) NOT NULL COMMENT '区县编码',`name` VARCHAR(40) NOT NULL COMMENT '区县名称',`cityCode` CHAR(6) NOT NULL COMMENT '所属城市编码') ENGINE=InnoDB DEFAULT CHARSET=UTF8 COMMENT='区县信息表';然后是省份信息表数据代码如下:INSERT INTO `t_address_province` V ALUES ('1', '110000', '北京市');INSERT INTO `t_address_province` V ALUES ('2', '120000', '天津市');INSERT INTO `t_address_province` V ALUES ('3', '130000', '河北省');INSERT INTO `t_address_province` V ALUES ('4', '140000', '山西省');INSERT INTO `t_address_province` V ALUES ('5', '150000', '内蒙古自治区');INSERT INTO `t_address_province` V ALUES ('6', '210000', '辽宁省');INSERT INTO `t_address_province` V ALUES ('7', '220000', '吉林省');INSERT INTO `t_address_province` V ALUES ('8', '230000', '黑龙江省');INSERT INTO `t_address_province` V ALUES ('9', '310000', '上海市');INSERT INTO `t_address_province` V ALUES ('10', '320000', '江苏省');INSERT INTO `t_address_province` V ALUES ('11', '330000', '浙江省');INSERT INTO `t_address_province` V ALUES ('12', '340000', '安徽省');INSERT INTO `t_address_province` V ALUES ('13', '350000', '福建省');INSERT INTO `t_address_province` V ALUES ('14', '360000', '江西省');INSERT INTO `t_address_province` V ALUES ('15', '370000', '山东省');INSERT INTO `t_address_province` V ALUES ('16', '410000', '河南省');INSERT INTO `t_address_province` V ALUES ('17', '420000', '湖北省');INSERT INTO `t_address_province` V ALUES ('18', '430000', '湖南省');INSERT INTO `t_address_province` V ALUES ('19', '440000', '广东省');INSERT INTO `t_address_province` V ALUES ('20', '450000', '广西壮族自治区'); INSERT INTO `t_address_province` V ALUES ('21', '460000', '海南省');INSERT INTO `t_address_province` V ALUES ('22', '500000', '重庆市');INSERT INTO `t_address_province` V ALUES ('23', '510000', '四川省');INSERT INTO `t_address_province` V ALUES ('24', '520000', '贵州省');INSERT INTO `t_address_province` V ALUES ('25', '530000', '云南省');INSERT INTO `t_address_province` V ALUES ('26', '540000', '西藏自治区'); INSERT INTO `t_address_province` V ALUES ('27', '610000', '陕西省');INSERT INTO `t_address_province` V ALUES ('28', '620000', '甘肃省');INSERT INTO `t_address_province` V ALUES ('29', '630000', '青海省');INSERT INTO `t_address_province` V ALUES ('30', '640000', '宁夏回族自治区'); INSERT INTO `t_address_province` V ALUES ('31', '650000', '新疆维吾尔自治区'); INSERT INTO `t_address_province` V ALUES ('32', '710000', '台湾省');INSERT INTO `t_address_province` V ALUES ('33', '810000', '香港特别行政区'); INSERT INTO `t_address_province` V ALUES ('34', '820000', '澳门特别行政区'); 下面是城市信息表数据代码如下:INSERT INTO `t_address_city` V ALUES ('1', '110100', '北京市', '110000'); INSERT INTO `t_address_city` V ALUES ('2', '1102xx', '北京下属县', '1100xx'); INSERT INTO `t_address_city` V ALUES ('3', '120100', '天津市', '120000'); INSERT INTO `t_address_city` V ALUES ('4', '1202xx', '天津下属县', '1200xx'); INSERT INTO `t_address_city` V ALUES ('5', '130100', '石家庄市', '130000'); INSERT INTO `t_address_city` V ALUES ('6', '130200', '唐山市', '130000'); INSERT INTO `t_address_city` V ALUES ('7', '130300', '秦皇岛市', '130000'); INSERT INTO `t_address_city` V ALUES ('8', '130400', '邯郸市', '130000'); INSERT INTO `t_address_city` V ALUES ('9', '130500', '邢台市', '130000'); INSERT INTO `t_address_city` V ALUES ('10', '130600', '保定市', '130000'); INSERT INTO `t_address_city` V ALUES ('11', '130700', '张家口市', '130000'); INSERT INTO `t_address_city` V ALUES ('12', '130800', '承德市', '130000'); INSERT INTO `t_address_city` V ALUES ('13', '130900', '沧州市', '130000'); INSERT INTO `t_address_city` V ALUES ('14', '131000', '廊坊市', '130000'); INSERT INTO `t_address_city` V ALUES ('15', '131100', '衡水市', '130000'); INSERT INTO `t_address_city` V ALUES ('16', '140100', '太原市', '140000'); INSERT INTO `t_address_city` V ALUES ('17', '140200', '大同市', '140000'); INSERT INTO `t_address_city` V ALUES ('18', '140300', '阳泉市', '140000'); INSERT INTO `t_address_city` VALUES ('19', '140400', '长治市', '140000'); INSERT INTO `t_address_city` V ALUES ('20', '140500', '晋城市', '140000'); INSERT INTO `t_address_city` V ALUES ('21', '140600', '朔州市', '140000'); INSERT INTO `t_address_city` V ALUES ('22', '140700', '晋中市', '140000'); INSERT INTO `t_address_city` V ALUES ('23', '140800', '运城市', '140000'); INSERT INTO `t_address_city` V ALUES ('24', '140900', '忻州市', '140000'); INSERT INTO `t_address_city` V ALUES ('25', '141000', '临汾市', '140000'); INSERT INTO `t_address_city` V ALUES ('26', '141100', '吕梁市', '140000'); INSERT INTO `t_address_city` V ALUES ('27', '150100', '呼和浩特市', '150000');INSERT INTO `t_address_city` V ALUES ('29', '150300', '乌海市', '150000');INSERT INTO `t_address_city` V ALUES ('30', '150400', '赤峰市', '150000');INSERT INTO `t_address_city` V ALUES ('31', '150500', '通辽市', '150000');INSERT INTO `t_address_city` V ALUES ('32', '150600', '鄂尔多斯市', '150000'); INSERT INTO `t_address_city` V ALUES ('33', '150700', '呼伦贝尔市', '150000'); INSERT INTO `t_address_city` V ALUES ('34', '150800', '巴彦淖尔市', '150000'); INSERT INTO `t_address_city` V ALUES ('35', '150900', '乌兰察布市', '150000'); INSERT INTO `t_address_city` V ALUES ('36', '152200', '兴安盟', '150000');INSERT INTO `t_address_city` V ALUES ('37', '152500', '锡林郭勒盟', '150000'); INSERT INTO `t_address_city` V ALUES ('38', '152900', '阿拉善盟', '150000'); INSERT INTO `t_address_city` V ALUES ('39', '210100', '沈阳市', '210000');INSERT INTO `t_address_city` V ALUES ('40', '210200', '大连市', '210000');INSERT INTO `t_address_city` V ALUES ('41', '210300', '鞍山市', '210000');INSERT INTO `t_address_city` V ALUES ('42', '210400', '抚顺市', '210000');INSERT INTO `t_address_city` VALUES ('43', '210500', '本溪市', '210000');INSERT INTO `t_address_city` V ALUES ('44', '210600', '丹东市', '210000');INSERT INTO `t_address_city` V ALUES ('45', '210700', '锦州市', '210000');INSERT INTO `t_address_city` V ALUES ('46', '210800', '营口市', '210000');INSERT INTO `t_address_city` V ALUES ('47', '210900', '阜新市', '210000');INSERT INTO `t_address_city` V ALUES ('48', '211000', '辽阳市', '210000');INSERT INTO `t_address_city` V ALUES ('49', '211100', '盘锦市', '210000');INSERT INTO `t_address_city` V ALUES ('50', '211200', '铁岭市', '210000');INSERT INTO `t_address_city` V ALUES ('51', '211300', '朝阳市', '210000');INSERT INTO `t_address_city` V ALUES ('52', '211400', '葫芦岛市', '210000'); INSERT INTO `t_address_city` V ALUES ('53', '220100', '长春市', '220000');INSERT INTO `t_address_city` V ALUES ('54', '220200', '吉林市', '220000');INSERT INTO `t_address_city` V ALUES ('55', '220300', '四平市', '220000');INSERT INTO `t_address_city` V ALUES ('56', '220400', '辽源市', '220000');INSERT INTO `t_address_city` V ALUES ('57', '220500', '通化市', '220000');INSERT INTO `t_address_city` V ALUES ('58', '220600', '白山市', '220000');INSERT INTO `t_address_city` V ALUES ('59', '220700', '松原市', '220000');INSERT INTO `t_address_city` V ALUES ('60', '220800', '白城市', '220000');INSERT INTO `t_address_city` V ALUES ('61', '222400', '延边朝鲜族自治州', '220000'); INSERT INTO `t_address_city` V ALUES ('62', '230100', '哈尔滨市', '230000'); INSERT INTO `t_address_city` V ALUES ('63', '230200', '齐齐哈尔市', '230000'); INSERT INTO `t_address_city` V ALUES ('64', '230300', '鸡西市', '230000');INSERT INTO `t_address_city` V ALUES ('65', '230400', '鹤岗市', '230000');INSERT INTO `t_address_city` V ALUES ('66', '230500', '双鸭山市', '230000'); INSERT INTO `t_address_city` V ALUES ('67', '230600', '大庆市', '230000');INSERT INTO `t_address_city` V ALUES ('68', '230700', '伊春市', '230000');INSERT INTO `t_address_city` V ALUES ('69', '230800', '佳木斯市', '230000'); INSERT INTO `t_address_city` V ALUES ('70', '230900', '七台河市', '230000'); INSERT INTO `t_address_city` V ALUES ('71', '231000', '牡丹江市', '230000');INSERT INTO `t_address_city` V ALUES ('73', '231200', '绥化市', '230000'); INSERT INTO `t_address_city` VALUES ('74', '232700', '大兴安岭地区', '230000'); INSERT INTO `t_address_city` V ALUES ('75', '310100', '上海市', '310000'); INSERT INTO `t_address_city` V ALUES ('76', '3102xx', '上海下属县', '3100xx'); INSERT INTO `t_address_city` V ALUES ('77', '320100', '南京市', '320000'); INSERT INTO `t_address_city` V ALUES ('78', '320200', '无锡市', '320000'); INSERT INTO `t_address_city` V ALUES ('79', '320300', '徐州市', '320000'); INSERT INTO `t_address_city` V ALUES ('80', '320400', '常州市', '320000'); INSERT INTO `t_address_city` VALUES ('81', '320500', '苏州市', '320000'); INSERT INTO `t_address_city` V ALUES ('82', '320600', '南通市', '320000'); INSERT INTO `t_address_city` V ALUES ('83', '320700', '连云港市', '320000'); INSERT INTO `t_address_city` V ALUES ('84', '320800', '淮安市', '320000'); INSERT INTO `t_address_city` V ALUES ('85', '320900', '盐城市', '320000'); INSERT INTO `t_address_city` V ALUES ('86', '321000', '扬州市', '320000'); INSERT INTO `t_address_city` V ALUES ('87', '321100', '镇江市', '320000'); INSERT INTO `t_address_city` V ALUES ('88', '321200', '泰州市', '320000'); INSERT INTO `t_address_city` V ALUES ('89', '321300', '宿迁市', '320000'); INSERT INTO `t_address_city` V ALUES ('90', '330100', '杭州市', '330000'); INSERT INTO `t_address_city` V ALUES ('91', '330200', '宁波市', '330000'); INSERT INTO `t_address_city` V ALUES ('92', '330300', '温州市', '330000'); INSERT INTO `t_address_city` V ALUES ('93', '330400', '嘉兴市', '330000'); INSERT INTO `t_address_city` V ALUES ('94', '330500', '湖州市', '330000'); INSERT INTO `t_address_city` V ALUES ('95', '330600', '绍兴市', '330000'); INSERT INTO `t_address_city` V ALUES ('96', '330700', '金华市', '330000'); INSERT INTO `t_address_city` V ALUES ('97', '330800', '衢州市', '330000'); INSERT INTO `t_address_city` V ALUES ('98', '330900', '舟山市', '330000'); INSERT INTO `t_address_city` V ALUES ('99', '331000', '台州市', '330000'); INSERT INTO `t_address_city` V ALUES ('100', '331100', '丽水市', '330000'); INSERT INTO `t_address_city` V ALUES ('101', '340100', '合肥市', '340000'); INSERT INTO `t_address_city` V ALUES ('102', '340200', '芜湖市', '340000'); INSERT INTO `t_address_city` V ALUES ('103', '340300', '蚌埠市', '340000'); INSERT INTO `t_address_city` V ALUES ('104', '340400', '淮南市', '340000'); INSERT INTO `t_address_city` V ALUES ('105', '340500', '马鞍山市', '340000'); INSERT INTO `t_address_city` V ALUES ('106', '340600', '淮北市', '340000'); INSERT INTO `t_address_city` V ALUES ('107', '340700', '铜陵市', '340000'); INSERT INTO `t_address_city` V ALUES ('108', '340800', '安庆市', '340000'); INSERT INTO `t_address_city` V ALUES ('109', '341000', '黄山市', '340000'); INSERT INTO `t_address_city` V ALUES ('110', '341100', '滁州市', '340000'); INSERT INTO `t_address_city` V ALUES ('111', '341200', '阜阳市', '340000'); INSERT INTO `t_address_city` V ALUES ('112', '341300', '宿州市', '340000'); INSERT INTO `t_address_city` V ALUES ('113', '341400', '巢湖市', '340000'); INSERT INTO `t_address_city` V ALUES ('114', '341500', '六安市', '340000'); INSERT INTO `t_address_city` V ALUES ('115', '341600', '亳州市', '340000');INSERT INTO `t_address_city` V ALUES ('117', '341800', '宣城市', '340000'); INSERT INTO `t_address_city` V ALUES ('118', '350100', '福州市', '350000'); INSERT INTO `t_address_city` V ALUES ('119', '350200', '厦门市', '350000'); INSERT INTO `t_address_city` V ALUES ('120', '350300', '莆田市', '350000'); INSERT INTO `t_address_city` V ALUES ('121', '350400', '三明市', '350000'); INSERT INTO `t_address_city` VALUES ('122', '350500', '泉州市', '350000'); INSERT INTO `t_address_city` V ALUES ('123', '350600', '漳州市', '350000'); INSERT INTO `t_address_city` V ALUES ('124', '350700', '南平市', '350000'); INSERT INTO `t_address_city` V ALUES ('125', '350800', '龙岩市', '350000'); INSERT INTO `t_address_city` V ALUES ('126', '350900', '宁德市', '350000'); INSERT INTO `t_address_city` V ALUES ('127', '360100', '南昌市', '360000'); INSERT INTO `t_address_city` V ALUES ('128', '360200', '景德镇市', '360000'); INSERT INTO `t_address_city` VALUES ('129', '360300', '萍乡市', '360000'); INSERT INTO `t_address_city` V ALUES ('130', '360400', '九江市', '360000'); INSERT INTO `t_address_city` V ALUES ('131', '360500', '新余市', '360000'); INSERT INTO `t_address_city` V ALUES ('132', '360600', '鹰潭市', '360000'); INSERT INTO `t_address_city` V ALUES ('133', '360700', '赣州市', '360000'); INSERT INTO `t_address_city` V ALUES ('134', '360800', '吉安市', '360000'); INSERT INTO `t_address_city` V ALUES ('135', '360900', '宜春市', '360000'); INSERT INTO `t_address_city` V ALUES ('136', '361000', '抚州市', '360000'); INSERT INTO `t_address_city` V ALUES ('137', '361100', '上饶市', '360000'); INSERT INTO `t_address_city` V ALUES ('138', '370100', '济南市', '370000'); INSERT INTO `t_address_city` V ALUES ('139', '370200', '青岛市', '370000'); INSERT INTO `t_address_city` V ALUES ('140', '370300', '淄博市', '370000'); INSERT INTO `t_address_city` V ALUES ('141', '370400', '枣庄市', '370000'); INSERT INTO `t_address_city` V ALUES ('142', '370500', '东营市', '370000'); INSERT INTO `t_address_city` V ALUES ('143', '370600', '烟台市', '370000'); INSERT INTO `t_address_city` V ALUES ('144', '370700', '潍坊市', '370000'); INSERT INTO `t_address_city` V ALUES ('145', '370800', '济宁市', '370000'); INSERT INTO `t_address_city` V ALUES ('146', '370900', '泰安市', '370000'); INSERT INTO `t_address_city` V ALUES ('147', '371000', '威海市', '370000'); INSERT INTO `t_address_city` V ALUES ('148', '371100', '日照市', '370000'); INSERT INTO `t_address_city` V ALUES ('149', '371200', '莱芜市', '370000'); INSERT INTO `t_address_city` V ALUES ('150', '371300', '临沂市', '370000'); INSERT INTO `t_address_city` V ALUES ('151', '371400', '德州市', '370000'); INSERT INTO `t_address_city` V ALUES ('152', '371500', '聊城市', '370000'); INSERT INTO `t_address_city` V ALUES ('153', '371600', '滨州市', '370000'); INSERT INTO `t_address_city` V ALUES ('154', '371700', '荷泽市', '370000'); INSERT INTO `t_address_city` V ALUES ('155', '410100', '郑州市', '410000'); INSERT INTO `t_address_city` V ALUES ('156', '410200', '开封市', '410000'); INSERT INTO `t_address_city` V ALUES ('157', '410300', '洛阳市', '410000'); INSERT INTO `t_address_city` V ALUES ('158', '410400', '平顶山市', '410000'); INSERT INTO `t_address_city` V ALUES ('159', '410500', '安阳市', '410000');INSERT INTO `t_address_city` V ALUES ('161', '410700', '新乡市', '410000');INSERT INTO `t_address_city` V ALUES ('162', '410800', '焦作市', '410000');INSERT INTO `t_address_city` V ALUES ('163', '410900', '濮阳市', '410000');INSERT INTO `t_address_city` V ALUES ('164', '411000', '许昌市', '410000');INSERT INTO `t_address_city` V ALUES ('165', '411100', '漯河市', '410000');INSERT INTO `t_address_city` V ALUES ('166', '411200', '三门峡市', '410000');INSERT INTO `t_address_city` V ALUES ('167', '411300', '南阳市', '410000');INSERT INTO `t_address_city` V ALUES ('168', '411400', '商丘市', '410000');INSERT INTO `t_address_city` V ALUES ('169', '411500', '信阳市', '410000');INSERT INTO `t_address_city` V ALUES ('170', '411600', '周口市', '410000');INSERT INTO `t_address_city` V ALUES ('171', '411700', '驻马店市', '410000');INSERT INTO `t_address_city` V ALUES ('172', '420100', '武汉市', '420000');INSERT INTO `t_address_city` V ALUES ('173', '420200', '黄石市', '420000');INSERT INTO `t_address_city` V ALUES ('174', '420300', '十堰市', '420000');INSERT INTO `t_address_city` V ALUES ('175', '420500', '宜昌市', '420000');INSERT INTO `t_address_city` V ALUES ('176', '420600', '襄樊市', '420000');INSERT INTO `t_address_city` V ALUES ('177', '420700', '鄂州市', '420000');INSERT INTO `t_address_city` V ALUES ('178', '420800', '荆门市', '420000');INSERT INTO `t_address_city` V ALUES ('179', '420900', '孝感市', '420000');INSERT INTO `t_address_city` VALUES ('180', '421000', '荆州市', '420000');INSERT INTO `t_address_city` V ALUES ('181', '421100', '黄冈市', '420000');INSERT INTO `t_address_city` V ALUES ('182', '421200', '咸宁市', '420000');INSERT INTO `t_address_city` V ALUES ('183', '421300', '随州市', '420000');INSERT INTO `t_address_city` VALUES ('184', '422800', '恩施土家族苗族自治州', '420000');INSERT INTO `t_address_city` V ALUES ('185', '429000', '省直辖行政单位', '420000');INSERT INTO `t_address_city` V ALUES ('186', '430100', '长沙市', '430000');INSERT INTO `t_address_city` V ALUES ('187', '430200', '株洲市', '430000');INSERT INTO `t_address_city` V ALUES ('188', '430300', '湘潭市', '430000');INSERT INTO `t_address_city` V ALUES ('189', '430400', '衡阳市', '430000');INSERT INTO `t_address_city` V ALUES ('190', '430500', '邵阳市', '430000');INSERT INTO `t_address_city` V ALUES ('191', '430600', '岳阳市', '430000');INSERT INTO `t_address_city` V ALUES ('192', '430700', '常德市', '430000');INSERT INTO `t_address_city` V ALUES ('193', '430800', '张家界市', '430000');INSERT INTO `t_address_city` V ALUES ('194', '430900', '益阳市', '430000');INSERT INTO `t_address_city` V ALUES ('195', '431000', '郴州市', '430000');INSERT INTO `t_address_city` V ALUES ('196', '431100', '永州市', '430000');INSERT INTO `t_address_city` V ALUES ('197', '431200', '怀化市', '430000');INSERT INTO `t_address_city` V ALUES ('198', '431300', '娄底市', '430000');INSERT INTO `t_address_city` VALUES ('199', '433100', '湘西土家族苗族自治州', '430000');INSERT INTO `t_address_city` V ALUES ('200', '440100', '广州市', '440000');INSERT INTO `t_address_city` V ALUES ('202', '440300', '深圳市', '440000');INSERT INTO `t_address_city` V ALUES ('203', '440400', '珠海市', '440000');INSERT INTO `t_address_city` V ALUES ('204', '440500', '汕头市', '440000');INSERT INTO `t_address_city` V ALUES ('205', '440600', '佛山市', '440000');INSERT INTO `t_address_city` V ALUES ('206', '440700', '江门市', '440000');INSERT INTO `t_address_city` V ALUES ('207', '440800', '湛江市', '440000');INSERT INTO `t_address_city` V ALUES ('208', '440900', '茂名市', '440000');INSERT INTO `t_address_city` V ALUES ('209', '441200', '肇庆市', '440000');INSERT INTO `t_address_city` V ALUES ('210', '441300', '惠州市', '440000');INSERT INTO `t_address_city` V ALUES ('211', '441400', '梅州市', '440000');INSERT INTO `t_address_city` V ALUES ('212', '441500', '汕尾市', '440000');INSERT INTO `t_address_city` V ALUES ('213', '441600', '河源市', '440000');INSERT INTO `t_address_city` VALUES ('214', '441700', '阳江市', '440000');INSERT INTO `t_address_city` V ALUES ('215', '441800', '清远市', '440000');INSERT INTO `t_address_city` V ALUES ('216', '441900', '东莞市', '440000');INSERT INTO `t_address_city` V ALUES ('217', '442000', '中山市', '440000');INSERT INTO `t_address_city` V ALUES ('218', '445100', '潮州市', '440000');INSERT INTO `t_address_city` V ALUES ('219', '445200', '揭阳市', '440000');INSERT INTO `t_address_city` V ALUES ('220', '445300', '云浮市', '440000');INSERT INTO `t_address_city` V ALUES ('221', '450100', '南宁市', '450000');INSERT INTO `t_address_city` V ALUES ('222', '450200', '柳州市', '450000');INSERT INTO `t_address_city` V ALUES ('223', '450300', '桂林市', '450000');INSERT INTO `t_address_city` V ALUES ('224', '450400', '梧州市', '450000');INSERT INTO `t_address_city` V ALUES ('225', '450500', '北海市', '450000');INSERT INTO `t_address_city` V ALUES ('226', '450600', '防城港市', '450000');INSERT INTO `t_address_city` V ALUES ('227', '450700', '钦州市', '450000');INSERT INTO `t_address_city` V ALUES ('228', '450800', '贵港市', '450000');INSERT INTO `t_address_city` V ALUES ('229', '450900', '玉林市', '450000');INSERT INTO `t_address_city` V ALUES ('230', '451000', '百色市', '450000');INSERT INTO `t_address_city` V ALUES ('231', '451100', '贺州市', '450000');INSERT INTO `t_address_city` V ALUES ('232', '451200', '河池市', '450000');INSERT INTO `t_address_city` V ALUES ('233', '451300', '来宾市', '450000');INSERT INTO `t_address_city` V ALUES ('234', '451400', '崇左市', '450000');INSERT INTO `t_address_city` V ALUES ('235', '460100', '海口市', '460000');INSERT INTO `t_address_city` V ALUES ('236', '460200', '三亚市', '460000');INSERT INTO `t_address_city` V ALUES ('237', '469000', '省直辖县级行政单位', '460000'); INSERT INTO `t_address_city` V ALUES ('238', '500100', '重庆市', '500000');INSERT INTO `t_address_city` V ALUES ('239', '5002xx', '重庆下属县', '5000xx'); INSERT INTO `t_address_city` V ALUES ('240', '5003xx', '重庆下属市', '5000xx'); INSERT INTO `t_address_city` VALUES ('241', '510100', '成都市', '510000');INSERT INTO `t_address_city` V ALUES ('242', '510300', '自贡市', '510000');INSERT INTO `t_address_city` V ALUES ('243', '510400', '攀枝花市', '510000');INSERT INTO `t_address_city` V ALUES ('244', '510500', '泸州市', '510000');。
C#comboBox实现省市两级联动(winform)
C#comboBox实现省市两级联动(winform)新建⼀个win form应⽤程序,拖两comboBox控件。
数据库见前⼀篇⽂章。
using System;using System.Collections.Generic;using ponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using System.Data.SqlClient;namespace省市{publicpartialclass Form1 : Form{public Form1(){InitializeComponent();}private void Form1_Load(object sender, EventArgs e){using (SqlConnection conn = new SqlConnection("server=.;database=DBPromary;user id=sa;password=123456")) {conn.Open();using (SqlCommand cmd = conn.CreateCommand()){mandText = "select proName from promary";using (SqlDataReader reader = cmd.ExecuteReader()){while (reader.Read()){string name = reader.GetString(reader.GetOrdinal("proName"));cb1.Items.Add(name);}}}}}privatevoid comboBox1_SelectedIndexChanged(object sender, EventArgs e){cb2.Items.Clear();using (SqlConnection conn =new SqlConnection("server=.;database=DBPromary;user id=sa;password=123456")){conn.Open();using (SqlCommand cmd = conn.CreateCommand()){mandText ="select cityName from city,promary where city.proID=promary.proID and promary.proName=@pname";cmd.Parameters.Add(new SqlParameter("pname",cb1.SelectedItem));using (SqlDataReader reader = cmd.ExecuteReader()){while (reader.Read()){string name = reader.GetString(reader.GetOrdinal("cityName"));cb2.Items.Add(name);}}}} } } }。
如何制作云表省市区三级联动
如何制作云表省市区三级联动我们在表单的填报过程中,经常需要填写省市区信息,如何实现快捷方便的联动填写呢?已有《省市区》模板,“省市区”数据批量导入;有以下3种实现方式:①下列列表联动②列表选择联动③树形列表联动一、下拉列表在“省份”上单击【﹀】从“省份下拉列表”中选择省份“江苏省”,在“城市”上单击【﹀】,弹出的下拉列表中只显示“江苏省下所有的城市列表”,选择“南京市”后,在“地区”上单击【﹀】,弹出的下拉列表中只显示“南京市下所有的地区列表”,实现联动实现分析:上图中以下拉列表的方式呈现数据,使用下拉列表的数据接口;省市区基础数据存放在《省市区》模板中,需要设计3个数据接口。
第1个数据接口“所有省份下拉列表”,没有参数,将所有的省份去重筛选出来,以便选择;第2个数据接口“根据省查询所有城市下拉列表”,有1个参数“省份”;第3个数据接口“根据省和城市查询所有地区下拉列表”,有2个参数“省份”和“城市”;在《客户档案》模板中调用已设计好的数据接口并给参数赋值;①在《省市区》模板中设计数据接口“省份下拉列表”。
该数据接口的类型为“下拉列表”,“取值”来自“数据表”“本模板”的“省份”数据项;②在《省市区》模板中设计数据接口“查询城市下拉列表(省份)”。
该数据接口的类型为“下拉列表”,“取值”来自“数据表”“本模板”的“城市”数据项;需要筛选指定“省份”的城市列表,设置“过滤设置”,选择“表达式过滤”,添加参数“省份”,并填写“过滤条件”;③在《省市区》模板中设计数据接口“查询地区下拉列表(省份,城市)”。
该数据接口的类型为“下拉列表”,“取值”来自“数据表”“本模板”的“地区”数据项;需要筛选指定“省份”和“城市”的城市列表,设置“过滤设置”,选择“表达式过滤”,添加参数“省份”和“城市”,并填写“过滤条件”;④在《客户档案》的填写规范中调用已设置的数据接口。
进入《客户档案》的模板设计界面,打开“数据定义管理”,在“省份”的填写规范上调用《省市区》的“省下拉列表”;⑤在“城市”的填写规范上调用《省市区》的“查询城市下拉列表(省份)”,该数据接口带有1个参数,将“本表单.省份”赋值给参数,并勾选“必填”,则只有当“本表单的省份”填写后,再单击城市的【﹀】才会运行该数据接口进行查询;⑥在“地区”的填写规范上调用《省市区》的“查询地区下拉列表(省份,城市)”,该数据接口带有2个参数,将“本表单.省份”和“本表单.城市”赋值给参数,并勾选“必填”,则只有当“本表单的省份和城市”都填写后,再单击地区的【﹀】才会运行该数据接口进行查询;这种实现方式用户需要单击进行选择,选项过多时,比较浪费时间,是否可以根据用户知道某几个字模糊查询并选择填写提高效率呢?二、列表选择联动在“省份”上填写内容后,下方根据填写的内容弹出模糊查询符合条件的省份列表,选择省份“广东省”,在“城市”上填写内容时,下方根据填写的内容在“广东省”内模查询符合条件的城市列表,在“地区”上填写内容后,下方根据填写的内容,在“广东省广州市”内模糊查询符合条件的地区列表;实现分析:省市区基础数据存放在《省市区》模板中,需要设计3个数据列表选择的数据接口,勾选“支持模糊查询”。
小程序省市区联动三种方法
小程序省市区联动三种方法一、通过接口获取省市区数据1.获取省份数据:从接口获取所有省份列表,返回一个包含所有省份信息的数组。
2.根据选中的省份获取城市数据:通过接口传递选中的省份ID,获取该省份下所有城市的列表,返回一个包含所有城市信息的数组。
3.根据选中的城市获取区域数据:通过接口传递选中的城市ID,获取该城市下所有区域的列表,返回一个包含所有区域信息的数组。
二、通过JSON数据获取省市区数据1.创建一个包含所有省份、城市和区域的JSON数据文件,格式如下:"province":"name": "省份1","city":"name": "城市1","area": ["区域1", "区域2", ...]},"name": "城市2","area": ["区域1", "区域2", ...]},...},"name": "省份2","city":"name": "城市1","area": ["区域1", "区域2", ...]},"name": "城市2","area": ["区域1", "区域2", ...]},...},...2. 通过AJAX请求获取JSON数据文件,并解析为一个包含所有省份、城市和区域信息的JavaScript对象。
3.根据选中的省份、城市,动态生成相应的区域选项。
从数据库查询数据进行联动(类似城市联动)
从数据库查询数据进⾏联动(类似城市联动)数据库⾃⼰定义,我⽤了四个框联动,选择了⼀个才会出现下⼀个,每⼀个都会去数据库查询⼀次。
但是⼀开始第⼀次的⽅法是查询⼀次,然后每次联动都⽤的最开始⼀次的数据查询,后来发现查询⼀次不能让联动点来点去,只能⼀次顺序过去,所以才每次都查询。
第⼀次:前端:<select id="first" class="select"onchange="firstSel()"></select><select class="select" id="second"></select><select class="select"id="third"></select><select class="select"id="fourth"></select>js:function firstSel(){//如果第⼀个下拉列表的值改变则调⽤此⽅法var province = $("#first").val();//得到第⼀个下拉列表的值$("#second").hide(); //初始化的时候第⼆个下拉列表隐藏$("#third").hide();$("#fourth").hide();url = "ShopGet";param = "{\"province\":\"" + province+ "\"}";jsonObj = JSON.parse(param);if(province!=null && "" != province&& 1 != province){//传递数据$.post(url,jsonObj,function(data){var res = JSON.parse(data);var newcity = [];var newarea= [];var newshop= [];var option="<option value='0'>"+"-城市-"+"</option>";$.each(res,function(i,n){//循环,i为下标从0开始,n为集合中对应的第i个对象if(newcity.indexOf(n.city) == -1) { //去掉重复值 newcity.push(n.city);option += "<option value='"+n.city+"'>"+n.city+"</option>" }});$("#second").html(option);//将循环拼接的字符串插⼊第⼆个下拉列表$("#second").show();//把第⼆个下拉列表展⽰$("#second").change(function () {//选择第⼆个框时$("#third").hide();$("#fourth").hide();//从前⾯重新选择时后⾯的选框要消失var city = $("#second").val();var option1="<option value='0'>"+"-市区-"+"</option>";/////for(i in newcity){//在城市数组中循环找到我选择的城市if(city==newcity[i]){//如果找到了就开始下⼀步$.each(res,function(i,n){//循环全部的数据库数据if(n.city==city) { //如果数据库中某个城市是我选择的就添加地区到地区数组if(newarea.indexOf(n.area) == -1){ newarea.push(n.area);option1 += "<option value='"+n.area+"'>"+n.area+"</option>" }}});}}$("#third").html(option1);//将循环拼接的字符串插⼊第⼆个下拉列表$("#third").show();//把第⼆个下拉列表展⽰$("#third").change(function () {var area = $("#third").val();var option2="<option value='0'>"+"-站点-"+"</option>";for(i in newarea){if(area==newarea[i]){$.each(res,function(i,n){if(n.area==area){if(newshop.indexOf(n.shop) == -1){ newshop.push(n.shop);option2 += "<option value='"+n.shop+"'>"+n.shop+"</option>" } } }); } }$("#fourth").html(option2);//将循环拼接的字符串插⼊第四个下拉列表$("#fourth").show();//把第四个下拉列表展⽰$("#fourth").change(function () {var shop=$("#fourth").val();alert(shop);});});});});}else {$("#second").hide();}}public ArrayList<Shop> ShopSelectD(Shop shop) throws SQLException {String sql = "select * from shop where 1=1 and province=?";pst = conn.prepareStatement(sql);pst.setString(1,shop.getProvince());mit();ResultSet rs = pst.executeQuery();ArrayList<Shop> ShopList = new ArrayList<Shop>();if(rs.next()){for(int i=0;i<=rs.getRow();i++){Shop shopTmp = new Shop();shopTmp.setId(rs.getInt("id"));shopTmp.setProvince(rs.getString("province"));shopTmp.setCity(rs.getString("city"));shopTmp.setArea(rs.getString("area"));shopTmp.setShop(rs.getString("shop"));ShopList.add(shopTmp);rs.next();}}return ShopList;}第⼆次:<select class="select"id="first2"name="first2" onchange="change(this)"></select><select class="select"id="second2"name="second2"onchange="change(this)"></select><select class="select"id="third2"name="third2"onchange="change(this)"></select><select class="select"id="fourth2"name="fourth2"onchange="change(this)"></select> function change(which){var type=null;var i=0;if(which.id=='first2'){$("#second2")[0].style.opacity = "0";$("#third2")[0].style.opacity = "0";$("#fourth2")[0].style.opacity = "0";var da =$('[name="first2"] option:selected').val();type="省会";id=2;}if(which.id=='second2'){$("#third2")[0].style.opacity = "0";$("#fourth2")[0].style.opacity = "0";var da = $("#second2").val();type="城市";id=3;}if(which.id=='third2'){var da = $("#third2").val();type="市区";id=4;}url = "ShopAllGet";param = "{\"date\":\"" +da+ "\",\"type\":\""+type+"\"}";jsonObj = JSON.parse(param);$.post(url,jsonObj,function(data){var res = JSON.parse(data);switch(id){case 2:option = "<option value='1'>"+"-城市-"+"</option>"$.each(res,function(i,n){//循环,i为下标从0开始,n为集合中对应的第i个对象option += "<option value='"+n.city+"'>"+n.city+"</option>" });$("#second2").html(option);//将循环拼接的字符串插⼊第⼆个下拉列表$("#second2")[0].style.opacity = "1"//把第⼆个下拉列表展⽰break;case 3:option = "<option value='1'>"+"-市区-"+"</option>"$.each(res,function(i,n){//循环,i为下标从0开始,n为集合中对应的第i个对象option += "<option value='"+n.area+"'>"+n.area+"</option>" });$("#third2").html(option);$("#third2")[0].style.opacity = "1"break;case 4:option="<option value='0'>"+"-站点-"+"</option>";$.each(res,function(i,n){option+= "<option value='"+n.shop+"'>"+n.shop+"</option>" });$("#fourth2").html(option);$("#fourth2")[0].style.opacity = "1"break;break;}});}if("省会".equals(type)){shop.setProvince(date);System.out.print("action");ArrayList<Shop> ShopList = shopSi.ShopFindS(shop);if(ShopList.isEmpty()){out.print("查询错误");//传值,否则查不到数据会报错}else{JSONArray ShopListMsg = JSONArray.fromObject(ShopList);out.print(ShopListMsg);System.out.print(ShopListMsg);}}else if("城市".equals(type)){shop.setCity(date);ArrayList<Shop> ShopList2 = shopSi.CityFindS(shop);if(ShopList2.isEmpty()){out.print("查询错误");//传值,否则查不到数据会报错}else{JSONArray ShopListMsg = JSONArray.fromObject(ShopList2);out.print(ShopListMsg);System.out.print(ShopListMsg);}}else if("市区".equals(type)){shop.setArea(date);ArrayList<Shop> ShopList3 = shopSi.AreaFindS(shop);if(ShopList3.isEmpty()){out.print("查询错误");//传值,否则查不到数据会报错}else{JSONArray ShopListMsg = JSONArray.fromObject(ShopList3);out.print(ShopListMsg);System.out.print(ShopListMsg);}}//多的话可以继续联动public ArrayList<Shop> ProvinceSelectD(Shop shop) throws SQLException{String sql = "select distinct province from shop;";//⽤了 distinct去重复,所以js可以不⽤数组来去重 pst = conn.prepareStatement(sql);mit();ResultSet rs = pst.executeQuery();ArrayList<Shop> ShopList = new ArrayList<Shop>();if(rs.next()){for(int i=0;i<=rs.getRow();i++){Shop shopTmp = new Shop();shopTmp.setProvince(rs.getString("province"));ShopList.add(shopTmp);rs.next();}}return ShopList;}。
省市联动数据库
--创建DBTblArea数据库create database DBTblAreause DBTblAreago--创建TblArea表create table TblArea(AreaId int primary key,AreaName varchar(50) not null,AreaPId int not null)---------------------------------------------------------------------------------------------------------------------------------------- --中国34个省级行政单位 23个省 5个自治区 4个直辖市 2特别行政区insert into TblArea values(1,'北京市',0)insert into TblArea values(2,'天津市',0)insert into TblArea values(3,'上海市',0)insert into TblArea values(4,'重庆市',0)insert into TblArea values(5,'河北省',0)insert into TblArea values(6,'山西省',0)insert into TblArea values(7,'台湾省',0)insert into TblArea values(8,'辽宁省',0)insert into TblArea values(9,'吉林省',0)insert into TblArea values(10,'黑龙江省',0)insert into TblArea values(11,'江苏省',0)insert into TblArea values(12,'浙江省',0)insert into TblArea values(13,'安徽省',0)insert into TblArea values(14,'福建省',0)insert into TblArea values(15,'江西省',0)insert into TblArea values(16,'山东省',0)insert into TblArea values(17,'河南省',0)insert into TblArea values(18,'湖北省',0)insert into TblArea values(19,'湖南省',0)insert into TblArea values(20,'广东省',0)insert into TblArea values(21,'甘肃省',0)insert into TblArea values(22,'四川省',0)insert into TblArea values(23,'贵州省',0)insert into TblArea values(24,'海南省',0)insert into TblArea values(25,'云南省',0)insert into TblArea values(26,'青海省',0)insert into TblArea values(27,'陕西省',0)insert into TblArea values(28,'广西壮族自治区',0)insert into TblArea values(29,'西藏自治区',0)insert into TblArea values(30,'宁夏回族自治区',0)insert into TblArea values(31,'新疆维吾尔自治区',0)insert into TblArea values(32,'内蒙古自治区',0)insert into TblArea values(33,'澳门特别行政区',0)insert into TblArea values(34,'香港特别行政区',0)------------------------------------------------------------------------------------------------------------------------------------------ --插入各个省的城市数据--4个直辖市insert into TblArea values(35,'北京市',1)insert into TblArea values(36,'天津市',2)insert into TblArea values(37,'上海市',3)insert into TblArea values(38,'重庆市',4)--5河北省(2005年辖:11个地级市,36个市辖区、22个县级市、108个县、6个自治县)insert into TblArea values(39,'石家庄市',5)insert into TblArea values(40,'唐山市',5)insert into TblArea values(41,'秦皇岛市',5)insert into TblArea values(42,'邯郸市',5)insert into TblArea values(43,'邢台市',5)insert into TblArea values(44,'保定市',5)insert into TblArea values(45,'张家口市',5)insert into TblArea values(46,'承德市',5)insert into TblArea values(47,'沧州市',5)insert into TblArea values(48,'廊坊市',5)insert into TblArea values(49,'衡水市',5)--6山西省11个城市insert into TblArea values(50,'太原市',6)insert into TblArea values(51,'大同市',6)insert into TblArea values(52,'阳泉市',6)insert into TblArea values(53,'长治市',6)insert into TblArea values(54,'晋城市',6)insert into TblArea values(55,'朔州市',6)insert into TblArea values(56,'晋中市',6)insert into TblArea values(57,'运城市',6)insert into TblArea values(58,'忻州市',6)insert into TblArea values(59,'临汾市',6)insert into TblArea values(60,'吕梁市',6)--7台湾省(台湾本岛与澎湖共设7市、16县,其中台北市与高雄市为“院辖市”,直属“行政院”,其余属台湾省;市下设区,县下设市(县辖市)、镇、乡,合称区市镇乡。
1.省市联动
</script>
</div>
</body>
</html>
核心代码如下:
var addressInit = function(_cmbProvince, _cmbCity, _cmbArea, defaultProvince, defaultCity, defaultArea)
{
var cmbProvince = document.getElementById(_cmbProvince);
var cmbCity = document.getElementById(_cmbCity);
var cmbArea = document.getElementById(_cmbArea);
{
cmbArea.options.length = 0;
if(cmbCity.selectedIndex == -1)return;
var item = cmbCity.options[cmbCity.selectedIndex].obj;
cmbProvince.onchange = changeProvince;
}
var provinceList = [
{name:'北京', cityList:[
{name:'市辖区', areaList:['东城区','西城区','崇文区','宣武区','朝阳区','丰台区','石景山区','海淀区','门头沟区','房山区','通州区','顺义区','昌平区','大兴区','怀柔区','平谷区']},
省市联动效果的简单实现代码(推荐)
省市联动效果的简单实现代码(推荐)下拉框⼆级联动效果在⽇常应⽤场景中经常会碰到,尤其是涉及地区、品种等有多级选项时。
例如:常见的省市联动下拉框,在选择省份时,城市列表也会更随改变。
思路:1,所谓联动效果,是指出发⽗级的数据变化时,会影响到关联性⼦级数据元素的变化。
下⾯是造的省市的数据:var linkDatas = {provinces:[{"code":"0","name":"请选择"},{"code":"1","name":"北京"},{"code":"2","name":"天津"},{"code":"3","name":"河北"},{"code":"4","name":"湖北"},{"code":"5","name":"⼴东"},{"code":"6","name":"其他"}],citys:{0:["请选择"],1:["朝阳区","海淀区","东城区","西城区","房⼭区","其他"],2:["天津"],3:["沧州","⽯家庄",4:["武汉市","宜昌市","襄樊市","其他"],5:["⼴州市","深圳市","汕头市","佛⼭市","珠海市","其他"],6:["其他"]}};2,根据数据动态⽣成option节点:function addOptions(target,options){var optionEle = null,target = target,option = options,optionLen = options.length;for(var i = 0;i < optionLen;i++){optionEle = document.createElement('option');optionEle.value = option[i].value;optionEle.text = option[i].text;target.options.add(optionEle);}}3,根据上述省市数据,其中code代表“省级”指向“城市”的标识符,当省级的数据变更时,出发change事件:pro.onchange = function(){console.log(this);var ct = city[this.value],ctLen = ct.length,ctBox = [];c.innerHTML = "";/*添加城市*/for(var j = 0;j < ctLen;j++){ctBox.push({"text" : ct[j],"value": ct[j]});}addOptions(c,ctBox);}HTML代码:<div class="content"><h3>下拉框联动效果</h3><p>省份:<select name="provinces" id="provinces"></select></p><p>市:<select name="citys" id="citys"></select></p></div>全部JavaScript代码:"code":"0","name":"请选择"},{"code":"1","name":"北京"},{"code":"2","name":"天津"},{"code":"3","name":"河北"},{"code":"4","name":"湖北"},{"code":"5","name":"⼴东"},{"code":"6","name":"其他"}],citys:{0:["请选择"],1:["朝阳区","海淀区","东城区","西城区","房⼭区","其他"],2:["天津"],3:["沧州","⽯家庄","秦皇岛","其他"],4:["武汉市","宜昌市","襄樊市","其他"],5:["⼴州市","深圳市","汕头市","佛⼭市","珠海市","其他"],6:["其他"]}};function addOptions(target,options){ var optionEle = null,target = target,option = options,optionLen = options.length;for(var i = 0;i < optionLen;i++){optionEle = document.createElement('option');optionEle.value = option[i].value;optionEle.text = option[i].text;target.options.add(optionEle);}}function provincesCitysLink(pro,c){var LD = linkDatas,provinces = LD.provinces,city = LD.citys,initCity = city[0],proBox = [];/*添加省份*/for(var i = 0;i < provinces.length;i++){proBox.push({"text" : provinces[i].name,"value": provinces[i].code})}addOptions(pro,proBox);/*初始化城市*/addOptions(c,[{"text" : initCity,"value": initCity}]);/*添加联动事件*/pro.onchange = function(){console.log(this);var ct = city[this.value],ctLen = ct.length,ctBox = [];c.innerHTML = "";/*添加城市*/for(var j = 0;j < ctLen;j++){ctBox.push({"text" : ct[j],"value": ct[j]});}addOptions(c,ctBox);}}var provinces = document.getElementById('provinces'),citys = document.getElementById('citys');provincesCitysLink(provinces,citys);以上这篇省市联动效果的简单实现代码(推荐)就是⼩编分享给⼤家的全部内容了,希望能给⼤家⼀个参考,也希望⼤家多多⽀持。
省市县区三级联动数据库
AddressCode ShortName ParentCode 110000北京市NULL110100北京市110000110101东城区110100110102西城区110100110103崇文区110100110104宣武区110100110105朝阳区110100110106丰台区110100110107石景山区110100110108海淀区110100110109门头沟区110100110111房山区110100110112通州区110100110113顺义区110100110114昌平区110100110115大兴区110100110116怀柔区110100110117平谷区110100110228密云县110200110229延庆县110200120000天津市NULL120101和平区120100120102河东区120100120103河西区120100120104南开区120100120105河北区120100120106红桥区120100120107塘沽区120100120108汉沽区120100120109大港区120100120110东丽区120100120111西青区120100120112津南区120100120113北辰区120100120114武清区120100120115宝坻区120100120221宁河县120200120223静海县120200120225蓟 县120200130000河北省NULL130100石家庄市130000130101市辖区130100130102长安区130100130103桥东区130100130104桥西区130100130105新华区130100130107井陉矿区130100130108裕华区130100130121井陉县130100130123正定县130100130124栾城县130100130128深泽县130100 130129赞皇县130100 130130无极县130100 130131平山县130100 130132元氏县130100 130133赵 县130100 130181辛集市130100 130182藁城市130100 130183晋州市130100 130184新乐市130100 130185鹿泉市130100 130200唐山市130000 130201市辖区130200 130202路南区130200 130203路北区130200 130204古冶区130200 130205开平区130200 130207丰南区130200 130208丰润区130200 130223滦 县130200 130224滦南县130200 130225乐亭县130200 130227迁西县130200 130229玉田县130200 130230唐海县130200 130281遵化市130200 130283迁安市130200 130300秦皇岛市130000 130301市辖区130300 130302海港区130300 130303山海关区130300 130304北戴河区130300 130321青龙满族自治县130300 130322昌黎县130300 130323抚宁县130300 130324卢龙县130300 130400邯郸市130000 130401市辖区130400 130402邯山区130400 130403丛台区130400 130404复兴区130400 130406峰峰矿区130400 130421邯郸县130400 130423临漳县130400 130424成安县130400 130425大名县130400 130426涉 县130400 130427磁 县130400 130428肥乡县130400 130429永年县130400 130430邱 县130400130434魏 县130400 130435曲周县130400 130481武安市130400 130500邢台市130000 130501市辖区130500 130502桥东区130500 130503桥西区130500 130521邢台县130500 130522临城县130500 130523内丘县130500 130524柏乡县130500 130525隆尧县130500 130526任 县130500 130527南和县130500 130528宁晋县130500 130529巨鹿县130500 130530新河县130500 130531广宗县130500 130532平乡县130500 130533威 县130500 130534清河县130500 130535临西县130500 130581南宫市130500 130582沙河市130500 130600保定市130000 130601市辖区130600 130602新市区130600 130603北市区130600 130604南市区130600 130621满城县130600 130622清苑县130600 130623涞水县130600 130624阜平县130600 130625徐水县130600 130626定兴县130600 130627唐 县130600 130628高阳县130600 130629容城县130600 130630涞源县130600 130631望都县130600 130632安新县130600 130633易 县130600 130634曲阳县130600 130635蠡 县130600 130636顺平县130600 130637博野县130600 130638雄 县130600 130681涿州市130600 130682定州市130600 130683安国市130600 130684高碑店市130600130702桥东区130700 130703桥西区130700 130705宣化区130700 130706下花园区130700 130721宣化县130700 130722张北县130700 130723康保县130700 130724沽源县130700 130725尚义县130700 130726蔚 县130700 130727阳原县130700 130728怀安县130700 130729万全县130700 130730怀来县130700 130731涿鹿县130700 130732赤城县130700 130733崇礼县130700 130800承德市130000 130801市辖区130800 130802双桥区130800 130803双滦区130800 130804鹰手营子矿区130800 130821承德县130800 130822兴隆县130800 130823平泉县130800 130824滦平县130800 130825隆化县130800 130826丰宁满族自治县130800 130827宽城满族自治县130800 130828围场满族蒙古族自治县130800 130900沧州市130000 130901市辖区130900 130902新华区130900 130903运河区130900 130921沧 县130900 130922青 县130900 130923东光县130900 130924海兴县130900 130925盐山县130900 130926肃宁县130900 130927南皮县130900 130928吴桥县130900 130929献 县130900 130930孟村回族自治县130900 130981泊头市130900 130982任丘市130900 130983黄骅市130900 130984河间市130900 131000廊坊市130000 131001市辖区131000 131002安次区131000 131003广阳区131000131024香河县131000 131025大城县131000 131026文安县131000 131028大厂回族自治县131000 131081霸州市131000 131082三河市131000 131100衡水市130000 131101市辖区131100 131102桃城区131100 131121枣强县131100 131122武邑县131100 131123武强县131100 131124饶阳县131100 131125安平县131100 131126故城县131100 131127景 县131100 131128阜城县131100 131181冀州市131100 131182深州市131100 140000山西省NULL 140100太原市140000 140101市辖区140100 140105小店区140100 140106迎泽区140100 140107杏花岭区140100 140108尖草坪区140100 140109万柏林区140100 140110晋源区140100 140121清徐县140100 140122阳曲县140100 140123娄烦县140100 140181古交市140100 140200大同市140000 140201市辖区140200 140202城 区140200 140203矿 区140200 140211南郊区140200 140212新荣区140200 140221阳高县140200 140222天镇县140200 140223广灵县140200 140224灵丘县140200 140225浑源县140200 140226左云县140200 140227大同县140200 140300阳泉市140000 140301市辖区140300 140302城 区140300 140303矿 区140300 140311郊 区140300 140321平定县140300 140322盂 县140300140411郊 区140400 140421长治县140400 140423襄垣县140400 140424屯留县140400 140425平顺县140400 140426黎城县140400 140427壶关县140400 140428长子县140400 140429武乡县140400 140430沁 县140400 140431沁源县140400 140481潞城市140400 140500晋城市140000 140501市辖区140500 140502城 区140500 140521沁水县140500 140522阳城县140500 140524陵川县140500 140525泽州县140500 140581高平市140500 140600朔州市140000 140601市辖区140600 140602朔城区140600 140603平鲁区140600 140621山阴县140600 140622应 县140600 140623右玉县140600 140624怀仁县140600 140700晋中市140000 140701市辖区140700 140702榆次区140700 140721榆社县140700 140722左权县140700 140723和顺县140700 140724昔阳县140700 140725寿阳县140700 140726太谷县140700 140727祁 县140700 140728平遥县140700 140729灵石县140700 140781介休市140700 140800运城市140000 140801市辖区140800 140802盐湖区140800 140821临猗县140800 140822万荣县140800 140823闻喜县140800 140824稷山县140800 140825新绛县140800 140826绛 县140800 140827垣曲县140800140881永济市140800 140882河津市140800 140900忻州市140000 140901市辖区140900 140902忻府区140900 140921定襄县140900 140922五台县140900 140923代 县140900 140924繁峙县140900 140925宁武县140900 140926静乐县140900 140927神池县140900 140928五寨县140900 140929岢岚县140900 140930河曲县140900 140931保德县140900 140932偏关县140900 140981原平市140900 141000临汾市140000 141001市辖区141000 141002尧都区141000 141021曲沃县141000 141022翼城县141000 141023襄汾县141000 141024洪洞县141000 141025古 县141000 141026安泽县141000 141027浮山县141000 141028吉 县141000 141029乡宁县141000 141030大宁县141000 141031隰 县141000 141032永和县141000 141033蒲 县141000 141034汾西县141000 141081侯马市141000 141082霍州市141000 141100吕梁市140000 141101市辖区141100 141102离石区141100 141121文水县141100 141122交城县141100 141123兴 县141100 141124临 县141100 141125柳林县141100 141126石楼县141100 141127岚 县141100 141128方山县141100 141129中阳县141100 141130交口县141100 141181孝义市141100150100呼和浩特市150000 150101市辖区150100 150102新城区150100 150103回民区150100 150104玉泉区150100 150105赛罕区150100 150121土默特左旗150100 150122托克托县150100 150123和林格尔县150100 150124清水河县150100 150125武川县150100 150200包头市150000 150201市辖区150200 150202东河区150200 150203昆都仑区150200 150204青山区150200 150205石拐区150200 150206白云矿区150200 150207九原区150200 150221土默特右旗150200 150222固阳县150200 150223达尔罕茂明安联合旗150200 150300乌海市150000 150301市辖区150300 150302海勃湾区150300 150303海南区150300 150304乌达区150300 150400赤峰市150000 150401市辖区150400 150402红山区150400 150403元宝山区150400 150404松山区150400 150421阿鲁科尔沁旗150400 150422巴林左旗150400 150423巴林右旗150400 150424林西县150400 150425克什克腾旗150400 150426翁牛特旗150400 150428喀喇沁旗150400 150429宁城县150400 150430敖汉旗150400 150500通辽市150000 150501市辖区150500 150502科尔沁区150500 150521科尔沁左翼中旗150500 150522科尔沁左翼后旗150500 150523开鲁县150500 150524库伦旗150500 150525奈曼旗150500 150526扎鲁特旗150500 150581霍林郭勒市150500 150600鄂尔多斯市150000150622准格尔旗150600 150623鄂托克前旗150600 150624鄂托克旗150600 150625杭锦旗150600 150626乌审旗150600 150627伊金霍洛旗150600 150700呼伦贝尔市150000 150701市辖区150700 150702海拉尔区150700 150721阿荣旗150700 150722莫力达瓦达斡尔族自治旗150700 150723鄂伦春自治旗150700 150724鄂温克族自治旗150700 150725陈巴尔虎旗150700 150726新巴尔虎左旗150700 150727新巴尔虎右旗150700 150781满洲里市150700 150782牙克石市150700 150783扎兰屯市150700 150784额尔古纳市150700 150785根河市150700 150800巴彦淖尔市150000 150801市辖区150800 150802临河区150800 150821五原县150800 150822磴口县150800 150823乌拉特前旗150800 150824乌拉特中旗150800 150825乌拉特后旗150800 150826杭锦后旗150800 150900乌兰察布市150000 150901市辖区150900 150902集宁区150900 150921卓资县150900 150922化德县150900 150923商都县150900 150924兴和县150900 150925凉城县150900 150926察哈尔右翼前旗150900 150927察哈尔右翼中旗150900 150928察哈尔右翼后旗150900 150929四子王旗150900 150981丰镇市150900 152200兴安盟150000 152201乌兰浩特市152200 152202阿尔山市152200 152221科尔沁右翼前旗152200 152222科尔沁右翼中旗152200 152223扎赉特旗152200 152224突泉县152200 152500锡林郭勒盟150000 152501二连浩特市152500152523苏尼特左旗152500 152524苏尼特右旗152500 152525东乌珠穆沁旗152500 152526西乌珠穆沁旗152500 152527太仆寺旗152500 152528镶黄旗152500 152529正镶白旗152500 152530正蓝旗152500 152531多伦县152500 152900阿拉善盟150000 152921阿拉善左旗152900 152922阿拉善右旗152900 152923额济纳旗152900 210000辽宁省NULL 210100沈阳市210000 210101市辖区210100 210102和平区210100 210103沈河区210100 210104大东区210100 210105皇姑区210100 210106铁西区210100 210111苏家屯区210100 210112东陵区210100 210113新城子区210100 210114于洪区210100 210122辽中县210100 210123康平县210100 210124法库县210100 210181新民市210100 210200大连市210000 210201市辖区210200 210202中山区210200 210203西岗区210200 210204沙河口区210200 210211甘井子区210200 210212旅顺口区210200 210213金州区210200 210224长海县210200 210281瓦房店市210200 210282普兰店市210200 210283庄河市210200 210300鞍山市210000 210301市辖区210300 210302铁东区210300 210303铁西区210300 210304立山区210300 210311千山区210300 210321台安县210300 210323岫岩满族自治县210300 210381海城市210300 210400抚顺市210000 210401市辖区210400210404望花区210400 210411顺城区210400 210421抚顺县210400 210422新宾满族自治县210400 210423清原满族自治县210400 210500本溪市210000 210501市辖区210500 210502平山区210500 210503溪湖区210500 210504明山区210500 210505南芬区210500 210521本溪满族自治县210500 210522桓仁满族自治县210500 210600丹东市210000 210601市辖区210600 210602元宝区210600 210603振兴区210600 210604振安区210600 210624宽甸满族自治县210600 210681东港市210600 210682凤城市210600 210700锦州市210000 210701市辖区210700 210702古塔区210700 210703凌河区210700 210711太和区210700 210726黑山县210700 210727义 县210700 210781凌海市210700 210782北宁市210700 210800营口市210000 210801市辖区210800 210802站前区210800 210803西市区210800 210804鲅鱼圈区210800 210811老边区210800 210881盖州市210800 210882大石桥市210800 210900阜新市210000 210901市辖区210900 210902海州区210900 210903新邱区210900 210904太平区210900 210905清河门区210900 210911细河区210900 210921阜新蒙古族自治县210900 210922彰武县210900 211000辽阳市210000 211001市辖区211000 211002白塔区211000 211003文圣区211000 211004宏伟区211000 211005弓长岭区211000 211011太子河区211000211021辽阳县211000 211081灯塔市211000 211100盘锦市210000 211101市辖区211100 211102双台子区211100 211103兴隆台区211100 211121大洼县211100 211122盘山县211100 211200铁岭市210000 211201市辖区211200 211202银州区211200 211204清河区211200 211221铁岭县211200 211223西丰县211200 211224昌图县211200 211281调兵山市211200 211282开原市211200 211300朝阳市210000 211301市辖区211300 211302双塔区211300 211303龙城区211300 211321朝阳县211300 211322建平县211300 211324喀喇沁左翼蒙古族自治县211300 211381北票市211300 211382凌源市211300 211400葫芦岛市210000 211401市辖区211400 211402连山区211400 211403龙港区211400 211404南票区211400 211421绥中县211400 211422建昌县211400 211481兴城市211400 220000吉林省NULL 220100长春市220000 220101市辖区220100 220102南关区220100 220103宽城区220100 220104朝阳区220100 220105二道区220100 220106绿园区220100 220112双阳区220100 220122农安县220100 220181九台市220100 220182榆树市220100 220183德惠市220100 220200吉林市220000 220201市辖区220200 220202昌邑区220200 220203龙潭区220200 220204船营区220200 220211丰满区220200 220221永吉县220200220281蛟河市220200 220282桦甸市220200 220283舒兰市220200 220284磐石市220200 220300四平市220000 220301市辖区220300 220302铁西区220300 220303铁东区220300 220322梨树县220300 220323伊通满族自治县220300 220381公主岭市220300 220382双辽市220300 220400辽源市220000 220401市辖区220400 220402龙山区220400 220403西安区220400 220421东丰县220400 220422东辽县220400 220500通化市220000 220501市辖区220500 220502东昌区220500 220503二道江区220500 220521通化县220500 220523辉南县220500 220524柳河县220500 220581梅河口市220500 220582集安市220500 220600白山市220000 220601市辖区220600 220602八道江区220600 220621抚松县220600 220622靖宇县220600 220623长白朝鲜族自治县220600 220625江源县220600 220681临江市220600 220700松原市220000 220701市辖区220700 220702宁江区220700 220721前郭尔罗斯蒙古族自治县220700 220722长岭县220700 220723乾安县220700 220724扶余县220700 220800白城市220000 220801市辖区220800 220802洮北区220800 220821镇赉县220800 220822通榆县220800 220881洮南市220800 220882大安市220800 222400延边朝鲜族自治州220000 222401延吉市222400 222402图们市222400 222403敦化市222400 222404珲春市222400222405龙井市222400 222406和龙市222400 222424汪清县222400 222426安图县222400 230000黑龙江NULL 230100哈尔滨市230000 230101市辖区230100 230102道里区230100 230103南岗区230100 230104道外区230100 230106香坊区230100 230107动力区230100 230108平房区230100 230109松北区230100 230111呼兰区230100 230123依兰县230100 230124方正县230100 230125宾 县230100 230126巴彦县230100 230127木兰县230100 230128通河县230100 230129延寿县230100 230181阿城市230100 230182双城市230100 230183尚志市230100 230184五常市230100 230200齐齐哈尔市230000 230201市辖区230200 230202龙沙区230200 230203建华区230200 230204铁锋区230200 230205昂昂溪区230200 230206富拉尔基区230200 230207碾子山区230200 230208梅里斯达斡尔族区230200 230221龙江县230200 230223依安县230200 230224泰来县230200 230225甘南县230200 230227富裕县230200 230229克山县230200 230230克东县230200 230231拜泉县230200 230281讷河市230200 230300鸡西市230000 230301市辖区230300 230302鸡冠区230300 230303恒山区230300 230304滴道区230300 230305梨树区230300 230306城子河区230300 230307麻山区230300 230321鸡东县230300 230381虎林市230300230382密山市230300 230400鹤岗市230000 230401市辖区230400 230402向阳区230400 230403工农区230400 230404南山区230400 230405兴安区230400 230406东山区230400 230407兴山区230400 230421萝北县230400 230422绥滨县230400 230500双鸭山市230000 230501市辖区230500 230502尖山区230500 230503岭东区230500 230505四方台区230500 230506宝山区230500 230521集贤县230500 230522友谊县230500 230523宝清县230500 230524饶河县230500 230600大庆市230000 230601市辖区230600 230602萨尔图区230600 230603龙凤区230600 230604让胡路区230600 230605红岗区230600 230606大同区230600 230621肇州县230600 230622肇源县230600 230623林甸县230600 230624杜尔伯特蒙古族自治县230600 230700伊春市230000 230701市辖区230700 230702伊春区230700 230703南岔区230700 230704友好区230700 230705西林区230700 230706翠峦区230700 230707新青区230700 230708美溪区230700 230709金山屯区230700 230710五营区230700 230711乌马河区230700 230712汤旺河区230700 230713带岭区230700 230714乌伊岭区230700 230715红星区230700 230716上甘岭区230700 230722嘉荫县230700 230781铁力市230700 230800佳木斯市230000 230801市辖区230800 230802永红区230800230803向阳区230800 230804前进区230800 230805东风区230800 230811郊 区230800 230822桦南县230800 230826桦川县230800 230828汤原县230800 230833抚远县230800 230881同江市230800 230882富锦市230800 230900七台河市230000 230901市辖区230900 230902新兴区230900 230903桃山区230900 230904茄子河区230900 230921勃利县230900 231000牡丹江市230000 231001市辖区231000 231002东安区231000 231003阳明区231000 231004爱民区231000 231005西安区231000 231024东宁县231000 231025林口县231000 231081绥芬河市231000 231083海林市231000 231084宁安市231000 231085穆棱市231000 231100黑河市230000 231101市辖区231100 231102爱辉区231100 231121嫩江县231100 231123逊克县231100 231124孙吴县231100 231181北安市231100 231182五大连池市231100 231200绥化市230000 231201市辖区231200 231202北林区231200 231221望奎县231200 231222兰西县231200 231223青冈县231200 231224庆安县231200 231225明水县231200 231226绥棱县231200 231281安达市231200 231282肇东市231200 231283海伦市231200 232700大兴安岭地区230000 232721呼玛县232700 232722塔河县232700 232723漠河县232700 310000上海市NULL 310100市辖区310000310101黄浦区310100 310103卢湾区310100 310104徐汇区310100 310105长宁区310100 310106静安区310100 310107普陀区310100 310108闸北区310100 310109虹口区310100 310110杨浦区310100 310112闵行区310100 310113宝山区310100 310114嘉定区310100 310115浦东新区310100 310116金山区310100 310117松江区310100 310118青浦区310100 310119南汇区310100 310120奉贤区310100 310200县310000 310230崇明县310200 320000江苏省NULL 320100南京市320000 320101市辖区320100 320102玄武区320100 320103白下区320100 320104秦淮区320100 320105建邺区320100 320106鼓楼区320100 320107下关区320100 320111浦口区320100 320113栖霞区320100 320114雨花台区320100 320115江宁区320100 320116六合区320100 320124溧水县320100 320125高淳县320100 320200无锡市320000 320201市辖区320200 320202崇安区320200 320203南长区320200 320204北塘区320200 320205锡山区320200 320206惠山区320200 320211滨湖区320200 320281江阴市320200 320282宜兴市320200 320300徐州市320000 320301市辖区320300 320302鼓楼区320300 320303云龙区320300 320304九里区320300 320305贾汪区320300 320311泉山区320300 320321丰 县320300320324睢宁县320300 320381新沂市320300 320382邳州市320300 320400常州市320000 320401市辖区320400 320402天宁区320400 320404钟楼区320400 320405戚墅堰区320400 320411新北区320400 320412武进区320400 320481溧阳市320400 320482金坛市320400 320500苏州市320000 320501市辖区320500 320502沧浪区320500 320503平江区320500 320504金阊区320500 320505虎丘区320500 320506吴中区320500 320507相城区320500 320581常熟市320500 320582张家港市320500 320583昆山市320500 320584吴江市320500 320585太仓市320500 320600南通市320000 320601市辖区320600 320602崇川区320600 320611港闸区320600 320621海安县320600 320623如东县320600 320681启东市320600 320682如皋市320600 320683通州市320600 320684海门市320600 320700连云港市320000 320701市辖区320700 320703连云区320700 320705新浦区320700 320706海州区320700 320721赣榆县320700 320722东海县320700 320723灌云县320700 320724灌南县320700 320800淮安市320000 320801市辖区320800 320802清河区320800 320803楚州区320800 320804淮阴区320800 320811清浦区320800 320826涟水县320800 320829洪泽县320800320900盐城市320000 320901市辖区320900 320902亭湖区320900 320903盐都区320900 320921响水县320900 320922滨海县320900 320923阜宁县320900 320924射阳县320900 320925建湖县320900 320981东台市320900 320982大丰市320900 321000扬州市320000 321001市辖区321000 321002广陵区321000 321003邗江区321000 321011郊 区321000 321023宝应县321000 321081仪征市321000 321084高邮市321000 321088江都市321000 321100镇江市320000 321101市辖区321100 321102京口区321100 321111润州区321100 321112丹徒区321100 321181丹阳市321100 321182扬中市321100。
数据库地区级联表
数据库地区级联表地区级联表(或地区层级联接表)是一个数据库架构模式,其中地区信息以层级方式存储,使得数据结构可以更好地表示地理位置的层次关系。
例如,一个国家下有多个省,每个省下又有多个市,每个市下又有多个区或县,依此类推。
实现地区级联表时,常见的做法如下:1.中心表:存储根级别的信息,例如国家信息。
2.子表:存储从属信息,例如省、市、区等。
这些子表通常会有一个外键指向中心表的主键,表示它们从属于哪个根实体。
3.关系表:有时为了表示层级关系,会使用一个关系表来存储父子关系。
以下是一个简单的例子,使用SQL描述一个国家、省、市三级联接的数据库结构:sql复制代码-- 中心表:国家CREATE TABLE Countries (country_id INT PRIMARY KEY,country_name VARCHAR(100));-- 子表:省份CREATE TABLE Provinces (province_id INT PRIMARY KEY,province_name VARCHAR(100),country_id INT,FOREIGN KEY (country_id) REFERENCES Countries(country_id));-- 子表:城市CREATE TABLE Cities (city_id INT PRIMARY KEY,city_name VARCHAR(100),province_id INT,FOREIGN KEY (province_id) REFERENCES Provinces(province_id) );使用这样的结构,你可以很容易地查询某个国家下的所有省份、某个省份下的所有城市等。
而且,如果你需要添加更多的层级(例如县、镇等),只需添加更多的子表和关系即可。
这种结构也便于维护和扩展。
关于全国省,市,区三级联动
关于全国省,市,区三级联动关于全国省,市,区三级联动我们见到的全国省,市,区三级联动不外乎有两种模式1 把所有数据存到js文件中2 使用数据库我们来说说这两种模式的优缺点吧第一种使用最多的,优点:不访问数据库速度比较快缺点:每次都要下载几百K的数据文件,只为了得到几十个B的数据第二种优点:数据传输量小,按需传输缺点:访问数据库有没有兼有两种优点的解决方案呢?答案是有的。
最近我就做了一个我给大家介绍一下我是怎么实现的使用ajax调用文本文件,把数据分成若干个文本文件,文件名使用编号,即身份证上那样的编号为每个省建一个文件夹名为省编号,例如北京编号为11,天津编号为12等在每个省级文件夹下建立一个和省级编号同名的文本文件文件的内容为:城市编号:城市名称城市编号:城市名称。
然后再在这个文件夹下建立以城市编号为文件名的文本文件内容如下:区县编号:区县名称区县编号:区县名称。
还要建立以个省列表文件(最外层)内容如下:11:北京市12:天津市13:河北省14:山西省15:内蒙古21:辽宁省22:吉林省23:黑龙江省31:上海市32:江苏省33:浙江省34:安徽省35:福建省36:江西省37:山东省41:河南省42:湖北省43:湖南省44:广东省45:广西46:海南省50:重庆市51:四川省52:贵州省53:云南省54:西藏61:陕西省62:甘肃省63:青海省64:宁夏65:新疆71:台湾81:香港82:澳门数字为option的value值文件为option的text值首先载入省级列表文件,当用户选择省份时触发onchange事件根据省份编码获取这个省份的城市列表文件并动态载入select中当用户选择城市的时候触发onchange事件根据城市编码获取这个城市的区县列表并动态载入整个过程只需载入三个文件,而每个文件的大小也就二三百B,也就是说只需1k左右的数据传输而把所有数据放到以个文件中最少要100多K算一算如果是一个门户网站,就算一天访问这样带选择省,市,区的页面有1000W的话每次下载所有数据:10000000X100K=10GX365=3650G(一年)按需下载:10000000X1K=0.1GX365=36.5G(一年)这只是一个网站的估计如果说全国所有网站都采用这种方法一年省下来的数据量是相当可观的可能有朋友要问了:这么多文件,难道要一个一个建立,一个一个输入吗,我开始的时候就准备这样做但后来想到了一个好的办法,我到国家统计局找到了行政规划的网页,保存了下来并用asp写了个程序生成文件,一次就可以把所有目录和文件建好,而且数据自动都保存进去了还是最新的。
省市区多级联动数据组合
省市区多级联动数据组合话不多说,直接说重点。
最近⽤到了省市区数据联动。
数据格式是这样的:$array = [0 => ['id' => 1,'pid' => 0,'name' => 't1',],1 => ['id' => 2,'pid' => 0,'name' => 't2',],2 => ['id' => 3,'pid' => 0,'name' => 't3',],3 => ['id' => 4,'pid' => 1,'name' => 't1-t4',],4 => ['id' => 5,'pid' => 2,'name' => 't2-t5',],5 => ['id' => 6,'pid' => 4,'name' => 't1-t4-t6',],];返回格式要求是这样的:Array([0] => Array([id] => 1[pid] => 0[name] => t1[child] => Array([0] => Array([id] => 4[pid] => 1[name] => t1-t4[child] => Array([0] => Array([id] => 6[pid] => 4[name] => t1-t4-t6)))))[1] => Array([id] => 2[pid] => 0[name] => t2[child] => Array([0] => Array([id] => 5[pid] => 2[name] => t2-t5)))[2] => Array([id] => 3[pid] => 0[name] => t3))在知道数组层级且层级⽐较少的情况下,最简单粗暴的⽅式当然是多层遍历组装数组。
全国省市县三级联动(数据完整版)
全国省市县三级联动(数据完整版)网页前台代码:<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Defaul t" EnableEventValidation="false"%><%@ Register assembly="AjaxControlToolkit"namespace="AjaxControlToolkit" tagprefix="cc1" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""/TR/xhtml 1/DTD/xhtml1-transitional.dtd"><html xmlns="/1999/xhtml"><head runat="server"><title>无标题页</title></head><body><form id="form1" runat="server"><div align="center"><asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager><fieldset ><legend>全国省市县</legend><fieldset style="width: 265px"><legend>省</legend><asp:DropDownList ID="DropDownList1" runat="server"AutoPostBack="True"></asp:DropDownList><cc1:CascadingDropDown ID="DropDownList1_CascadingDropDown" runat="server"Category="provice" Enabled="True" LoadingText="读取数据中.." PromptText="请选择省"TargetControlID="DropDownList1" ServicePath="WebService.asmx" ServiceMethod ="GetproviceNames"></cc1:CascadingDropDown></fieldset><fieldset style="width: 266px"><legend>市</legend><asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True"></asp:DropDownList><cc1:CascadingDropDown ID="DropDownList2_CascadingDropDown" runat="server"Category="city" Enabled="True" TargetControlID="DropDownList2" LoadingText="读取数据中.." PromptText="请选择市" ParentControlID="DropDownList1"ServicePath="WebService.asmx" ServiceMethod="GetCityNames"></cc1:CascadingDropDown></fieldset><fieldset style="width: 266px"><legend>县</legend><asp:DropDownList ID="DropDownList3" runat="server"></asp:DropDownList><cc1:CascadingDropDown ID="DropDownList3_CascadingDropDown" runat="server" Ca tegory="District" TargetControlID="DropDownList3"Enabled="True" LoadingText="读取数据中.." ParentControlID="DropDownList2"ServicePath="WebService.asmx" ServiceMethod="GetDistrictNames"></cc1:CascadingDropDown></fieldset></fieldset></div></form></body></html>WebService代码using System;using System.Collections;using System.Linq;using System.Web;using System.Web.Services;using System.Web.Services.Protocols;using System.Xml.Linq;//访问数据库命名空间using System.Data;using System.Data.SqlClient;//访问web.config命名空间using System.Web.Configuration;//导入ScriptServiceAttribute类的命名空间using System.Web.Script.Services;//返回CascadingDropDownNameValue数组所需的命名空间using AjaxControlToolkit;using System.Collections.Generic;using System.Collections.Specialized;///<summary>///WebService 的摘要说明///</summary>[WebService(Namespace = "/")][WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]//若要允许使用 AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
省市区三级联动
string sheng = context.Request.Form["Province"] == null ? "" : context.Request.Form["Province"]; string str = "select * from cities where provinceid='" + sheng + "'"; using (SqlDataAdapter ada = new SqlDataAdapter(str, conn)) {
$("#sheng").val("赋值"); GetShi();
$("#Shi").val("赋值"); GetQu(); $("@Qu").val("赋值"); }
})
function GetSheng() { $("#Sheng").empty(); $("#Sheng").append("<option value='0'>请选择</option>"); $.ajax({ type: "post", url: "GetJsonData.ashx", datatype: "josn", //数据类型 data: "type=GetProvince", async: false, //把异步改为同步 success: function (data) { var GetData = eval(data); //转一下型,GetData相当于一张表的模型了,打点就可以调用字段 $.each(GetData, function (i, item) { $("#Sheng").append("<option value='" + item.provinceid + "'>" + item.province + "</option>"); }) } }) GetShi();
地名地址数据省市联动更新方法探究
地名地址数据省市联动更新方法探究
石娜
【期刊名称】《山东国土资源》
【年(卷),期】2022(38)3
【摘要】为了解决目前公众对地理信息公共服务平台地名地址数据现势性要求越来越高而传统基础测绘更新速度较慢、周期较长之间的矛盾,本文结合滨州市区的地名地址更新实例,探索了一种基于共享本底数据库的省、市联动协同更新策略,通过合理的任务区划分,按照统一的更新要求,实践有所侧重的核查更新策略,实现了地名地址数据的省、市协同共享,显著提高了山东省地理信息公共服务平台数据的准确性和专业性,加强了用户体验,为平台更广泛和深入的应用奠定了基础。
【总页数】5页(P76-80)
【作者】石娜
【作者单位】山东省国土测绘院
【正文语种】中文
【中图分类】P208
【相关文献】
1.地名地址数据要素级增量更新与融合方法研究
2.基于业务联动的地名地址数据协同更新方法
3.多源地名地址数据融合更新技术方法研究
4.地名地址与专题数据联动更新技术研究
5.面向公众版“天地图”的地名地址数据库动态更新方法
因版权原因,仅展示原文概要,查看原文内容请购买。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
--创建DBTblArea数据库create database DBTblAreause DBTblAreago--创建TblArea表create table TblArea(AreaId int primary key,AreaName varchar(50) not null,AreaPId int not null)---------------------------------------------------------------------------------------------------------------------------------------- --中国34个省级行政单位 23个省 5个自治区 4个直辖市 2特别行政区insert into TblArea values(1,'北京市',0)insert into TblArea values(2,'天津市',0)insert into TblArea values(3,'上海市',0)insert into TblArea values(4,'重庆市',0)insert into TblArea values(5,'河北省',0)insert into TblArea values(6,'山西省',0)insert into TblArea values(7,'台湾省',0)insert into TblArea values(8,'辽宁省',0)insert into TblArea values(9,'吉林省',0)insert into TblArea values(10,'黑龙江省',0)insert into TblArea values(11,'江苏省',0)insert into TblArea values(12,'浙江省',0)insert into TblArea values(14,'福建省',0)insert into TblArea values(15,'江西省',0)insert into TblArea values(16,'山东省',0)insert into TblArea values(17,'河南省',0)insert into TblArea values(18,'湖北省',0)insert into TblArea values(19,'湖南省',0)insert into TblArea values(20,'广东省',0)insert into TblArea values(21,'甘肃省',0)insert into TblArea values(22,'四川省',0)insert into TblArea values(23,'贵州省',0)insert into TblArea values(24,'海南省',0)insert into TblArea values(25,'云南省',0)insert into TblArea values(26,'青海省',0)insert into TblArea values(27,'陕西省',0)insert into TblArea values(28,'广西壮族自治区',0)insert into TblArea values(29,'西藏自治区',0)insert into TblArea values(30,'宁夏回族自治区',0)insert into TblArea values(31,'新疆维吾尔自治区',0)insert into TblArea values(32,'内蒙古自治区',0)insert into TblArea values(33,'澳门特别行政区',0)insert into TblArea values(34,'香港特别行政区',0)------------------------------------------------------------------------------------------------------------------------------------------ --插入各个省的城市数据--4个直辖市insert into TblArea values(35,'北京市',1)insert into TblArea values(37,'上海市',3)insert into TblArea values(38,'重庆市',4)--5河北省(2005年辖:11个地级市,36个市辖区、22个县级市、108个县、6个自治县)insert into TblArea values(39,'石家庄市',5)insert into TblArea values(40,'唐山市',5)insert into TblArea values(41,'秦皇岛市',5)insert into TblArea values(42,'邯郸市',5)insert into TblArea values(43,'邢台市',5)insert into TblArea values(44,'保定市',5)insert into TblArea values(45,'张家口市',5)insert into TblArea values(46,'承德市',5)insert into TblArea values(47,'沧州市',5)insert into TblArea values(48,'廊坊市',5)insert into TblArea values(49,'衡水市',5)--6山西省11个城市insert into TblArea values(50,'太原市',6)insert into TblArea values(51,'大同市',6)insert into TblArea values(52,'阳泉市',6)insert into TblArea values(53,'长治市',6)insert into TblArea values(54,'晋城市',6)insert into TblArea values(55,'朔州市',6)insert into TblArea values(56,'晋中市',6)insert into TblArea values(57,'运城市',6)insert into TblArea values(58,'忻州市',6)insert into TblArea values(59,'临汾市',6)--7台湾省(台湾本岛和澎湖共设7市、16县,其中台北市和高雄市为“院辖市”,直属“行政院”,其余属台湾省;市下设区,县下设市(县辖市)、镇、乡,合称区市镇乡。
)insert into TblArea values(61,'台北市',7)insert into TblArea values(62,'高雄市',7)insert into TblArea values(63,'基隆市',7)insert into TblArea values(64,'台中市',7)insert into TblArea values(65,'台南市',7)insert into TblArea values(66,'新竹市',7)insert into TblArea values(67,'嘉义市',7)insert into TblArea values(68,'台北县',7)insert into TblArea values(69,'宜兰县',7)insert into TblArea values(70,'桃园县',7)insert into TblArea values(71,'新竹县',7)insert into TblArea values(72,'苗栗县',7)insert into TblArea values(73,'台中县',7)insert into TblArea values(74,'彰化县',7)insert into TblArea values(75,'南投县',7)insert into TblArea values(76,'云林县',7)insert into TblArea values(77,'嘉义县',7)insert into TblArea values(78,'台南县',7)insert into TblArea values(79,'高雄县',7)insert into TblArea values(80,'屏东县',7)insert into TblArea values(81,'澎湖县',7)insert into TblArea values(82,'台东县',7)insert into TblArea values(83,'花莲县',7)--8辽宁省(2006年,辖:14个地级市;56个市辖区、17个县级市、19个县、8个自治县。
)insert into TblArea values(84,'沈阳市',8)insert into TblArea values(85,'大连市',8)insert into TblArea values(86,'鞍山市',8)insert into TblArea values(87,'抚顺市',8)insert into TblArea values(88,'本溪市',8)insert into TblArea values(89,'丹东市',8)insert into TblArea values(90,'锦州市',8)insert into TblArea values(91,'营口市',8)insert into TblArea values(92,'阜新市',8)insert into TblArea values(93,'辽阳市',8)insert into TblArea values(94,'盘锦市',8)insert into TblArea values(95,'铁岭市',8)insert into TblArea values(96,'朝阳市',8)insert into TblArea values(97,'葫芦岛市',8)--9吉林省(2006年,辖:8个地级市、1个自治州;20个市辖区、20个县级市、17个县、3个自治县。