无法使用 PHP 递归函数显示面包屑导航

发布于 2024-12-01 10:32:04 字数 1759 浏览 2 评论 0原文

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

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

任何帮助将不胜感激。过去几个月我一直在寻找线索。

非常感谢!

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

谢谢。

If anyone can help me with display breadcrumbs using recursive function method in PHP.

I got this code :

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]) . ' » ';
        }
}

But, when i click on any links (categories), the breadcrumb didn't show up.
If there any mistake about the show breadcrumb code?

Any help would be appreciate. I already looking for clue for the last couple months.

Many thanks !

EDIT :
Code to display not using the "for" command.

   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> >";
    }
}

To show the breadcrumb, i must type manually the function and the id number. Like this:

echo getCategoryTreeIDs(20);

My question is, how i can display the breadcrumb automatically when some users click on the categories id?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

知足的幸福 2024-12-08 10:32:04

要动态显示请求页面的面包屑,您需要检查 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
}

To display breadcrumbs dynamically for requested pages, you will need to examine the q GET parameter.

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
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文