I am doing a sort of Shopping Cart project with PHP and MySQL. Yes, I know there are many open source projects. This is for my learning of PHP and MySql and web dev in general.
So I wanted to make a side bar with categories for the products. Some may be under one category while others may be under several subcategories and what not.
To do this, I plan on have a Product table with a Category ID column linked to a Category Table that consists of ID and Category Varchar. The category varchar will have its subcategories split up using a sequence:
ex: (Yes, tomato is also a fruit) The '//' in Category Table tells us that it is a subcategory.
Product Table
- ID | Name | ... | Category ID
- 0 | cherry tomato pack of 5 | ... | 0
- 1 | cherry tomato individual| ... | 0
- 2 | cherry tomato dozen | ... | 0
- 3 | sundried cherry tomato 1 lb| ... | 2
Category Table
- ID | Category
- 0 | Vegetable//Tomato//Cherry
- 1 | Vegetable//Tomato//Beefsteak
- 2 | Vegetable//Tomato//Sundried//Cherry
- 3 | Vegetable//Tomato//Sundried//Beefsteak
So for the sidebar, is it advisable to do :
SELECT category FROM categoryTable
Each time a page with the sidebar is called and have the sidebar rendered with php? Or is there a better way to do this?
Also, if a search function is implemented, should I just be searching all products in the productTable or is there a better way?
Lastly, when selecting a category to view all items under the same category, is it advisable to go through the whole productTable and only view those with applicable CategoryID?
Thanks everyone for the tips! This is my first time doing MySQL and PHP stuff so any help/tips are greatly appreciated. Please provide some insight if any of you professionals have any different ideas as to approaching this project. Thanks!