0

I'm trying to build a webshop from scratch so I can learn a bit of web development.

I have created a layout that is static that I want to make dynamic with php. Im starting with the menu system. I have different categories that make the top menu level in my mega menu, then I have the subcategories that make the first level in the menu, then I have the products, now to my question.

Question: Is there a general practice for a way that I design the database to make it easy to build the menu? Right now I have a table that is named "products" that have 4 columns:

id name description category(number)

Should I add the subcategory to the same table? Which other tables should I have if I dont put all the info in one table? Hope my question make sense...

You can view my menu system here: http://www.reclam.se

Roman Frolov
  • 998
  • 11
  • 18
Heresh
  • 305
  • 1
  • 4
  • 18
  • Take out good old pen and paper and write down what information you want to store about whatever object within your project. Create tables when values show up multiple times. A rule of thumb would be, if you were to make any changes in naming or something you should only have to change it in one place. – RST Feb 18 '17 at 00:10
  • So you mean I should have it static if it is not used more than once? – Heresh Feb 18 '17 at 00:12
  • Building a webshop is not exactly the best way to learn web development, as your main problem right now is how to design the database. For this I suggest you read up on database design practices in a book on the subject. I recommend https://www.pearsonhighered.com/program/Connolly-Database-Systems-A-Practical-Approach-to-Design-Implementation-and-Management-6th-Edition/PGM116956.html – jake2389 Feb 18 '17 at 00:12
  • No that is not what I meant. For example, if you were to use the category name with every product that is in it, this name would have to be changed (not manually) in several places in case you change your mind about it. So category name is a value qualified to store in a different table. Analyze all the information you want to store. – RST Feb 18 '17 at 10:56

1 Answers1

1

You're searching for techniques like "nested sets" or "adjacency list". These are concepts how to represent tree structures in a database.

A good start for using an adjacency list may be this article: How do you convert a parent-child (adjacency) table to a nested set using PHP and MySQL?

For your products you should use a different database table.

Community
  • 1
  • 1
StefanSL
  • 318
  • 2
  • 11