为了账号安全,请及时绑定邮箱和手机立即绑定

正在回答

1 回答

<?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('&nbsp;',$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);

?>

纯自写<--!>

1 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

有源码下载吗

我要回答 关注问题
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号