面包屑导航

问题描述

| 您能帮我得到这份面包屑的导航工作吗?我的php不好。我还在学习。 这是我在mysql中的猫
cats_id   cats_position   cats_parentid 

1            1>                0
2            1>2>              1
3            3>                0
4            1>2>4>            2
我尝试过类似的方法,但这不是正确的方法。你能告诉我正确的方法吗?
$pieces = explode(\">\",$position);

if ($pieces[0] != \"\")
{

 $result = mysql_query(\"SELECT * FROM cats
 WHERE cats_id=\'$pieces[0]\'\");
 while($row = mysql_fetch_array($result))
   {
$piecesid0 = $row[\'cats_id\'];
$piecesname0 = $row[\'cats_name\'];
$piecesposition0 = $row[\'cats_position\'];
   }
}
if ($pieces[1] != \"\")
{
 $result = mysql_query(\"SELECT * FROM cats
 WHERE cats_id=\'$pieces[1]\'\");
 while($row = mysql_fetch_array($result))
   {
$piecesid1 = $row[\'cats_id\'];
$piecesname1 = $row[\'cats_name\'];
$piecesposition1 = $row[\'cats_position\'];
   }
}
if ($pieces[2] != \"\")
{
 $result = mysql_query(\"SELECT * FROM cats
 WHERE cats_id=\'$pieces[2]\'\");
 while($row = mysql_fetch_array($result))
   {
$piecesid2 = $row[\'cats_id\'];
$piecesname2 = $row[\'cats_name\'];
$piecesposition2 = $row[\'cats_position\'];
   }
}
if ($pieces[3] != \"\")
{
 $result = mysql_query(\"SELECT * FROM cats
 WHERE cats_id=\'$pieces[3]\'\");
 while($row = mysql_fetch_array($result))
   {
$piecesid3 = $row[\'cats_id\'];
$piecesname3 = $row[\'cats_name\'];
$piecesposition3 = $row[\'cats_position\'];
   }
}
?>
<a href=\"index.php\">Index</a> > 

<a href=\"cats.php?cat=<?=$piecesid0;?>&parent=0&position=<?=$piecesposition0;?>\"><?=$piecesname0;?></a>

<?
If ($piecesid1 != \"\")
{
?>
> <a href=\"cats.php?cat=<?=$piecesid1;?>&parent=<?=$piecesid0;?>&position=<?=$piecesposition1;?>\"><?=$piecesname1;?></a>
<?
}
?>
<?
If ($piecesid2 != \"\")
{
?>
> <a href=\"cats.php?cat=<?=$piecesid2;?>&parent=<?=$piecesid1;?>&position=<?=$piecesposition2;?>\"><?=$piecesname2;?></a>
<?
}
?>
<?
If ($piecesid3 != \"\")
{
?>
> <a href=\"cats.php?cat=<?=$piecesid3;?>&parent=<?=$piecesid2;?>&position=<?=$piecesposition3;?>\"><?=$piecesname3;?></a>
<?
}
?>
    

解决方法

        在这里查看嵌套的set模型: http://mikehillyer.com/articles/managing-hierarchical-data-in-mysql/ 这就是CakePHP实施Tree行为的方式,这是我用于面包屑的方式。他们添加了parent_id列作为嵌套集的增强版本。 如果太重,则可以使用邻接表模型:http://kod34fr33.wordpress.com/2008/05/06/adjacency-list-tree-on-mysql/     

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...