简体   繁体   English

通过自引用表创建面包屑

[英]create breadcrumbs by self-referencing table

Is it possible to create breadcrumbs list on my website product page using PHP from table self-referencing structure. 是否可以通过表自引用结构使用PHP在我的网站产品页面上创建面包屑列表。

I try to loop from product to get the root category but the result is backward. 我尝试从产品循环获得根类别,但结果是落后的。 or I try to get root category first and loop it but I can't know which one is the correct child to reach the product that I wanted to show. 还是我尝试先获取根目录类别并将其循环播放,但是我不知道哪个是适合我想要展示的产品的正确孩子。

Well there can be different way in different frameworks. 好吧,在不同的框架中可以有不同的方式。 I assume you are speaking about core PHP. 我假设您正在谈论核心PHP。 You can write a recursive function to get parents from database until you get to the root category. 您可以编写一个递归函数以从数据库获取父级,直到您到达根目录类别为止。 Put the title/id in an array and at the end user array_reverse function to reverse the order of elements in array. 将标题/标识放在数组中,并在最终用户array_reverse函数中,以反转数组中元素的顺序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM