search
Homephp教程PHP源码Thinkphp realizes three-level linkage between provinces and municipalities

One table realizes three-level linkage of provinces and municipalities [3409 pieces of data]

public function index(){
    $province = M('Tree')->where ( array('pid'=>1) )->select ();
    $this->assign('province',$province);
    $this->display();
 
}
public function getRegion(){
    $Region=M("Tree");
    $map['pid']=$_REQUEST["pid"];
    $map['type']=$_REQUEST["type"];
    $list=$Region->where($map)->select();
    echo json_encode($list);
}
<select name="province" id="province" onchange="loadRegion(&#39;province&#39;,2,&#39;city&#39;,&#39;{:U(&#39;Index/getRegion&#39;)}&#39;);">
   <option value="0" selected>省份/直辖市</option><volist name="province" id="vo">
   <option value="{$vo.id}" >{$vo.name}</option></volist>
</select>         
<select name="city" id="city"  onchange="loadRegion(&#39;city&#39;,3,&#39;town&#39;,&#39;{:U(&#39;Index/getRegion&#39;)}&#39;);">
  <option value="0">市/县</option>
</select>
<select name="town" id="town">
  <option value="0">镇/区</option>
</select>
function loadRegion(sel,type_id,selName,url){
    jQuery("#"+selName+" option").each(function(){
        jQuery(this).remove();
    });
    jQuery("<option value=0>请选择</option>").appendTo(jQuery("#"+selName));
    if(jQuery("#"+sel).val()==0){
        return;
    }
    jQuery.getJSON(url,{pid:jQuery("#"+sel).val(),type:type_id},
        function(data){
            if(data){
                jQuery.each(data,function(idx,item){
                    jQuery("<option value="+item.id+">"+item.name+"</option>").appendTo(jQuery("#"+selName));
                });
            }else{
                jQuery("<option value=&#39;0&#39;>请选择</option>").appendTo(jQuery("#"+selName));
            }
        }
    );
}
</script>
DROP TABLE IF EXISTS `tp_tree`;
CREATE TABLE `tp_tree` (
  `id` int(5) unsigned NOT NULL AUTO_INCREMENT,
  `pid` int(5) unsigned NOT NULL DEFAULT &#39;0&#39;,
  `name` varchar(120) DEFAULT NULL,
  `type` tinyint(1) DEFAULT &#39;2&#39;,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=3410 DEFAULT CHARSET=utf8;
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools