0
----------------------------------------------------------------------------------
|id_category|parent_id|category_level|category_sort|category_name|category_rw_tag|
|--------------------------------------------------------------------------------|
|1          |0        |1             |NULL         |Shopping     |NULL           |
|2          |1        |2             |NULL         |Laptops      |NULL           |
|3          |2        |3             |NULL         |Accessories  |NULL           |
|4          |3        |4             |NULL         |HDD          |NULL           |
----------------------------------------------------------------------------------

I have a table of categories. to the configuration shown above. Fist of my problem : I would like to build a breadcrumb like this :

Shopping > Laptops > Accesories > HDD

Second : the breadcrumb. must be dynamic! so when I query the db table with parameter id_category= 5 to display :

Shopping > Laptops > Accesories > HDD

when I query the db table with parameter id_category= 4

Shopping > Laptops > Accesories

...and so on.

I have read all question regarding my question but simply I had no idea how to d this.

Php Jedy's you are my only Hope.

2 Answers 2

1

you would have to do some queries to retrieve each category until you hit a root category (i.e parent_id = 0). so in your example you would query category with id = 4, check the row parent_id is not equal to zero so query the next category with the parent_id and so on.

If your ecommerce website doesn't have too much categories that would be ok, if you have more than 5 levels of categories I would advice to make a breadscrumb field in your table with an already formated text.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank's.I just add one more column to store ascendants.Job done.
0

Your question is a logical duplicate of What is the best practice for fetching a tree of nodes from a database for further rendering.

There is a long list of articles and resources you can use.

1 Comment

Thank's.Too complex for my qualification. I just add one more column to store ascendants.Job done.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.