Skip to content

Instantly share code, notes, and snippets.

@anotherxx
Created August 16, 2017 22:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anotherxx/4e5eab7390352f931682ac96fd301625 to your computer and use it in GitHub Desktop.
Save anotherxx/4e5eab7390352f931682ac96fd301625 to your computer and use it in GitHub Desktop.
For categories:
ID | Name | Parent_ID
(Parent ID is for category tree)
For products:
ID | Category_ID | Name | Description | Other
Let's say the category tree is like
Computers [ID: 1 | Parent: 0]
|-Laptops [ID: 2 | Parent: 1]
|-Desktop [ID: 3 | Parent: 1]
|-Printers [ID: 4 | Parent: 1]
| |-Brand #1 [ID: 5 | Parent: 4]
| |-Brand #2 [ID: 6 | Parent: 4]
|-Other stuff [ID: 7 | Parent: 1]
Then, if you want to display all products from from, for example, Printers, just do a recursion getting all items from Printers category and its subcategories.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment