1
如果任何人都可以使用PHP中的遞歸函數方法幫助我顯示麪包屑。無法使用遞歸函數顯示Breadcrumb PHP
我得到這個代碼:
function getCategoryTreeIDs($qs_type_id) {
$crumbsql = "SELECT parent_id FROM lists WHERE id=$qs_type_id";
$crumbresult = tep_db_query($crumbsql);
$crumbrow = tep_db_fetch_array($crumbresult);
$path = array();
if (!$crumbrow['parent_id'] == '') {
$path[] = $crumbrow['parent_id'];
$path = array_merge($this->getCategoryTreeIDs($crumbrow['parent_id']), $path);
}
return $path;
}
function showCatBreadCrumb($qs_type_id) {
$array = $this->getCategoryTreeIDs($qs_type_id);
$numItems = count($array);
for ($i = 0; $i<=$numItems-1; $i++) {
echo $this->getNameLink($array[$i]) . ' » ';
}
}
但是,當我點擊任何鏈接(類別),麪包屑沒有露面。 如果顯示麪包屑代碼有任何錯誤?
任何幫助將不勝感激。我已經在尋找過去幾個月的線索。
非常感謝!
編輯: 代碼顯示不使用「for」命令。
function getCategorytTreeIDs($qs_type_id) {
global $lists;
$crumbsql = "SELECT * FROM lists WHERE id=$qs_type_id";
$crumbresult = mysql_query($crumbsql);
$crumbrow = mysql_fetch_array($crumbresult);
if($crumbrow['parent_id'] == 0) {
$crumbprob = $crumbrow['problem'];
return "<a href='index.php'>Home</a> > <a href='index.php?q=id/$qs_type_id'>".$crumbprob."</a> > ";
} else {
$crumbprob = $crumbrow['problem'];
return getCategoryTreeIDs($crumbrow['parent_id']). "<a href='index.php?q=id/$qs_type_id'>".$crumbprob."</a> >";
}
}
要顯示麪包屑,我必須手動輸入函數和ID號。就像這樣:
echo getCategoryTreeIDs(20);
我的問題是,我怎麼能自動顯示麪包屑時,一些用戶在類別ID點擊?
謝謝。
有一點要注意的是,當這個工作時,最後一個麪包屑會出現一個raquo。我建議獲取麪包屑和內爆數組('»',$ breadcrumbs)'而不是用於。 –
爲什麼不嘗試一些調試。從第一個功能開始。 'print_r($ crumbrow)'來確保它包含你所期望的。另外,您確實意識到沒有任何麪包屑是鏈接,是正確的?你提到點擊類別,但我認爲你的意思是在其他地方。 –
我遵循你的建議,通過改變「for」命令。看到上面的帖子。 – Erick