不能使用PHP递归函数显示面包屑



如果有人可以帮助我在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]) . ' &raquo; ';
        }
}

但是,当我点击任何链接(类别)时,面包屑没有显示。show breadcrumb代码是否有错误?

任何帮助都将是感激的。我已经找了几个月的线索了。

谢谢!

编辑:不使用"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时,如何自动显示面包屑?

谢谢。

要动态显示所请求页面的面包屑,您需要检查q GET参数。

list($qName, $qID) = explode('/', $_GET['q']); // for categories qName will be 
                                               // 'id' and qID will the be id
if($qName == 'id') {
    echo getCategoryTreeIDs($qID); //Outputs breadcrumbs for category pages
}

最新更新