Lookup in same table with PHP

neojiphre

New Member
I want to create a breadcrumb navigation on my pages, but I have very little knowledge of PHP and MySQL. Here is my situation. I have a table of categories, with a row named 'cat_parent_id' that tells ID of the parent category (there are first level AND second level categories). If the category has no parent ID, it's 'cat_parent_id' is set to 0, meaning that it's a first level category.

2mr9rte.png


So, I would like some help on how to code the PHP for my breadcrumb navigation. I have a page named index.php and whenever I navigate to a category page, the URL becomes 'index.php?c=18' (for category with an ID of 18). I want to use this to create an if statement, that checks if category has parent_id of 0 to only display:

Home >> Category_Name

for my breadcrumbs. If the parent_id is greater than 0, then lookup the name of the category with the ID in the database, then append the name of the current category, eg:

Home >> Parent_Category_Name >> Current_Category_Name

Please some help guys :)
 

MarkR

New Member
You could create a function which calls the row from the database of the parent id of the current category and put the function in a loop which keeps calling itself and appending the result to the bread crumb trail until the parent is 0.
 
Top