面包屑分类
<?php require_once('./db.php'); //面包屑类型分类 $id = isset($_GET['id'])?$_GET['id']:false; if (!$id){ echo '<script>window.location.href="./03.php?id=1"</script>'; }else{ function getCatePath($id=1,&$arr = []){ $func = __FUNCTION__; if (!$id){ dir('不能为0'); } $sql = "select * from deepcate where id=$id"; $res = mysqli_fetch_assoc(query($sql)); $arr[] = $res; if ($res['pid']){ $func($res['pid'],$arr); } return $arr; } $arr = array_reverse(getCatePath($id)); if (empty($arr[0]['id'])){ die('id无效'); }else{ foreach ($arr as $key=>$val){ echo "<a href='./03.php?id={$arr[$key]['id']}'>{$arr[$key]['catename']}</a>".">"; } } }