Search code examples
phpbreadcrumbsself-referencing-table

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.

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.


Solution

  • Well there can be different way in different frameworks. I assume you are speaking about core 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.