dongzhang4301 2016-08-17 00:25
浏览 21

我应该每次都处理MySql表还是做不同的事情?

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!

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 matlab中使用gurobi时报错
    • ¥15 WPF 大屏看板表格背景图片设置
    • ¥15 这个主板怎么能扩出一两个sata口
    • ¥15 不是,这到底错哪儿了😭
    • ¥15 2020长安杯与连接网探
    • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
    • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
    • ¥16 mybatis的代理对象无法通过@Autowired装填
    • ¥15 可见光定位matlab仿真
    • ¥15 arduino 四自由度机械臂