效果如下
操作如下
打开include/post.func.php 找到
- function get_area_select($title = '', $areaid = 0, $extend = '', $deep = 0, $id = 1) {
- global $db;
- $parents = array();
- if($areaid) {
- $r = $db->get_one("SELECt child,arrparentid FROM {$db->pre}area WHERe areaid=$areaid");
- $parents = explode(',', $r['arrparentid']);
- if($r['child']){
- $parents[] = $areaid;
- }
- } else {
- $parents[] = 0;
- }
- $select = '';
- foreach($parents as $k=>$v) {
- if($deep && $deep <= $k) break;
- $v = intval($v);
- $select .= '<selectload_area(this.value, '.$id.');" '.$extend.'>';
- if($title) $select .= '<option value="'.$v.'">'.$title.'</option>';
- $result = $db->query("SELECT areaid,areaname FROM {$db->pre}area WHERe parentid=$v ORDER BY listorder,areaid ASC");
- while($a = $db->fetch_array($result)) {
- $selectid = isset($parents[$k+1]) ? $parents[$k+1] : $areaid;
- $selected = $a['areaid'] == $selectid ? ' selected' : '';
- $select .= '<option value="'.$a['areaid'].'"'.$selected.'>'.$a['areaname'].'</option>';
- }
- $select .= '</select> ';
- }
- return $select;
- }
将原代码修改成下面的代码
- function get_area_select($title = '', $areaid = 0, $extend = '', $deep = 0, $id = 1) {
- global $db;
- $parents = array();
- $i = 0;
- if($areaid) {
- $r = $db->get_one("SELECT child,arrparentid FROM {$db->pre}area WHERe areaid=$areaid");
- $parents = explode(',', $r['arrparentid']);
- if($r['child']){
- $parents[] = $areaid;
- }else{
- $i = 1;
- }
- } else {
- $parents[] = 0;
- $i = 1;
- }
- $select = '';
- foreach($parents as $k=>$v) {
- if($deep && $deep <= $k) break;
- $v = intval($v);
- $select .= '<selectload_area(this.value, '.$id.');" '.$extend.'>';
- if($title) $select .= '<option value="'.$v.'">'.$title.'</option>';
- $result = $db->query("SELECT areaid,areaname FROM {$db->pre}area WHERe parentid=$v ORDER BY listorder,areaid ASC");
- while($a = $db->fetch_array($result)) {
- $selectid = isset($parents[$k+1]) ? $parents[$k+1] : $areaid;
- $selected = $a['areaid'] == $selectid ? ' selected' : '';
- $select .= '<option value="'.$a['areaid'].'"'.$selected.'>'.$a['areaname'].'</option>';
- }
- $select .= '</select> ';
- }
- if($i){
- $select .= '<select '.$extend.'>';
- $select .= '<option value=" "'.$selected.'>所在城市</option>';
- $select .= '</select> ';
- }
- return $select;
- }