weixin_慕瓜6241313
2016-12-25 19:35
求下载地址
<?php
function getList($pid=0,&$res=array(),$spac=0){
$spac=$spac+4;
$link=mysqli_connect('localhost','root','root') or die('没有链接到服务器');
mysqli_select_db($link,'deepcate') or die("没有链接到表");
$sql="select * from cate where pid={$pid}";
$rows=mysqli_query($link, $sql);
if($rows){
while($row=mysqli_fetch_assoc($rows)){
$row['catename']=str_repeat(' ',$spac).'|--'.$row['catename'];
$res[]=$row;
getList($row['id'],$res,$spac);
}
return $res;
}
}
function showList($pid=0,$select){
$result=getList($pid);
echo "<select name='cate'>";
foreach ($result as $key => $value) {
$selecstr='';
if($value['id']==$select){
$selectstr='selected';
}
echo "<option {$selectstr} >{$value['catename']}</option>";
}
}
function getCatePath($id,&$res=array(),$spac=0){
$spac=1;
$link=mysqli_connect('localhost','root','root') or die('没有链接到服务器');
mysqli_select_db($link,'deepcate') or die("没有链接到表");
$sql="select * from cate where id={$id}";
$rows= mysqli_query($link, $sql);
if($rows){
while($row=mysqli_fetch_assoc($rows)){
$row['catename']=$row['catename'].str_repeat('>',$spac);
$res[]=$row;
getCatePath($row['pid'],$res,$spac);
}
krsort($res);
return $res;
}
}
function showCatePath($id){
$res=getCatePath($id);
foreach ($res as $key => $value) {
echo "<a href='cate.php?cid={$value['id']}'>{$value['catename']}</a>";
}
}
showCatePath(10);
?>
纯自写<--!>
PHP无限级分类技术
30088 学习 · 84 问题
相似问题