数据表数据源的省市区联动:
原始数据:
//获取所有学校信息 $school=D('school'); $info=$school->getList();
数据如下:
1 => array 'id' => string '2' (length=1) 'school_name' => string '仲恺农业工程学院' (length=24) 'province' => string '6' (length=1) 'city' => string '76' (length=2) 'region' => string '696' (length=3) 'address' => string '仲恺路500号' (length=15)
现在有数据表region:
转换很简单的啦:
public function school_list(){ $region=D('region'); $region_info=$region->select(); //获取所有学校信息 $school=D('school'); $info=$school->getList(); /***讲省市区id转换成中文字符***/ foreach($info as $key=>$value){ foreach($region_info as $kk => $vv){ if($vv['region_id']==$value['province']){ $info[$key]['province']=$vv['region_name']; } } foreach($region_info as $kk => $vv){ if($vv['region_id']==$value['city']){ $info[$key]['city']=$vv['region_name']; } } foreach($region_info as $kk => $vv){ if($vv['region_id']==$value['region']){ $info[$key]['region']=$vv['region_name']; } } } /***将省市区id转换成中文字符***/
哈哈,原来我居然想着用连表进行查询换取数据。