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); }
省份/直辖市 {$vo.name} 市/县 镇/区
function loadregion(sel,type_id,selname,url){ jquery(#+selname+ option).each(function(){ jquery(this).remove(); }); jquery(请选择).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(+item.name+).appendto(jquery(#+selname)); }); }else{ jquery(请选择).appendto(jquery(#+selname)); } } ); }
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 '0', `name` varchar(120) default null, `type` tinyint(1) default '2', primary key (`id`) ) engine=myisam auto_increment=3410 default charset=utf8;