云彩无色3804005
2017-08-04 09:32
<?php
require_once('connect.php');
function getList($pid=0,&$result=array(),$spac=0){
$spac = $spac + 2;
$sql="select * from forwardcate WHERE pid='$pid' ";
$query=mysqli_query($con,$sql);
if($query&&mysqli_num_rows($query)){
while($row = mysqli_fetch_assoc($query)){
$row['catename'] = str_repeat(' ',$spac).'|--'.$row['catename'];
$result[] = $row;
getList($row['id'],$result,$spac);
}
}
return $result;
}
function displayCate($pid=0,$selected=1){
$rs = getList($pid);
$str='';
$str.= "<select name='cate'>";
foreach($rs as $key => $val){
$selectedstr = '';
if($val['id'] == $selected){
$sellectedstr ="selected";
}
$str.= "<option {$selectedstr}>{$val['catename']}</option>";
}
return $str .= '</select>';
}
echo displayCate(0,1);
?>
函数内部不能调用$con变量,改为$query=mysqli_query($GLOBALS[con],$sql);
大家看看这个是什么原因?
PHP无限级分类技术
30076 学习 · 83 问题
相似问题