PHP 无限极分类下拉列表实现
程序员文章站
2023-10-23 23:28:13
1. 递归实现下拉列表 ......
1. 递归实现下拉列表
/** * @param 递归 实现下拉列表 分类 */ include('db.inc.php'); function getlist($pid = 0,&$result = array(), $spac = 0){ $spac = $spac + 2; $sql = "select * from deepcate where pid = $pid"; $res = mysql_query($sql); while($row = mysql_fetch_array($res)){ $row['catename'] = str_repeat(' ',$spac).'|--'.$row['catename']; $result[] = $row; getlist($row['id'],$result,$spac); } return $result; } function displaycate($pid=0,$select = 0){ $rs = getlist($pid); $str .= "<select name = 'cate'>"; foreach ($rs as $key => $val) { $selected = ''; if($val['id'] == $selected){ $selected = "selected"; } $str .= "<option {$selected}>{$val['catename']}</option>"; } return $str .= '</select>' } echo displaycate(0);
上一篇: 我们生活中哪些是激素类食物
下一篇: 怎么凉拌黄瓜才好吃