php部分:
function build_select($array,$select='',$showAll=0){
$tmp = array();
if($showAll == 1){
$tmp[] = "<option value='*'>不限</option>";
}elseif($showAll == 2){
$tmp[] = "<option value='0'>选择</option>";
}
foreach ((array)$array as $key => $val) {
if($select == $key){
$tmp[] = "<option selected value='{$key}'>{$val}</option>";
}else{
$tmp[] = "<option value='{$key}'>{$val}</option>";
}
}
return implode("", $tmp);
}
public function index(){
$cid = intval(I('get.classid'));
$map = array();
$arrList = D("School")->where($map)->order("orderval ASC")->getField("id,name");
$select = funs_build_select($arrList,$cid,1);
$this->assign('selectClass', $select);
}
html部分:
<select name="school" id="school">
{$select}
</select>
复制代码