老师记得将代码传上来啊
老师记得将代码传上来啊
老师记得将代码传上来啊
2014-11-17
<?php include 'conn.php'; function getList($pid=0,&$result=array(),$spac=0) { $spac=$spac+4; $sql="select * from `catalog` where `pid`='$pid'"; $res= mysql_query($sql); while($row= mysql_fetch_assoc($res)) { $row['catalogname']= str_repeat(' ', $spac).'|--'.$row['catalogname']; $result[]=$row; getList($row['id'],$result,$spac); } return $result; } function displayCatalog($pid=0,$selected=0) { $rs=getList($pid); $str.="<select name='catalog'>"; foreach ($rs as $key=>$val) { $selectedstr=''; if($val['id']==$selected){ $selectedstr="selected"; } $str.="<option ".$selectedstr.">".$val['catalogname']."</option>"; } $str.="</select>"; return $str; } echo displayCatalog(0,2); echo displayCatalog(0); ?>
举报