2011-05-27 162 views
0

你能幫我弄這個麪包屑導航工作嗎?我的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> 
<? 
} 
?> 
+3

大笑貓版:我用HAZ德breadcrubmz問題 – 2011-05-27 19:34:39

回答