-2

I am little bit confused that how I have to create the tables for simple shopping website because I am new in php and this is my first project of shopping website choosen by myself for practice but I am confused with the size of the products and color of the products and different types of the products like laptops, mobile, jeans, shirts etc,

I have created the table but I want to know that two things

  1. for electronics products I have to create a different table and for

  2. clothes like jeans and shirts etc, I have to create a different table

    Please can anybody tell me the structure of the table.

Community
  • 1
  • 1
Owaiz Yusufi
  • 849
  • 1
  • 14
  • 34
  • Possible duplicate of [designing database to hold different metadata information](http://stackoverflow.com/questions/3241033/designing-database-to-hold-different-metadata-information) – Ilker Mutlu Nov 14 '16 at 09:16
  • create a table for products and just add a column for the different types. like `product_type: eletronics|shirts|etc` – Semi-Friends Nov 14 '16 at 09:17
  • You are jumping the gun, Start small, I suggest you start with small php applications, and get more practice more and more before jumping to databases. – Masivuye Cokile Nov 14 '16 at 09:27
  • @ Masivuye Cokile I have practice for 5 months – Owaiz Yusufi Nov 14 '16 at 09:29

2 Answers2

2

You'll have many tables, for example:

Products:
    ID
    Name
    Description
    Etc...

Categories:
    ID
    Name

ProductCategories:
    ProductID
    CategoryID

Types:
    ID
    Name

ProductTypes:
    ProductID
    TypeID

This enables you to have products in multiple categories and of multiple types...

Added further examples as per the comment below. For sizes you have a Sizes table, and a mapping table to map products to sizes...

Sizes:
    ID
    Name

ProductSizes:
    ProductID
    SizeID

If you also need to consider colours, and need to make a choice whether you will store sizes that have a colour, or colours that have a size...

Colours:
    ID
    Name

ProductColours
    ProductID
    ColourID

Or, if you need colours and sizes, or any further complexity, i would abstract it right out and use a ProductAttributes way of doing it, maybe out of the scope of this question as the answer would be quite lengthy indeed.

But in the same style as above, you could have a table like so:

ProductSizesColours:
    ProductID
    SizeID
    ColourID

Which enables you to store data for products such as:

A pair of jeans that are size 32 and colour brown. A juice blenderthat is 3 litre size and colour white. Etc...

Stuart
  • 6,630
  • 2
  • 24
  • 40
  • But if a product of a brand like levis shirt have the same model but different size and different colours how can i manage this in database – Owaiz Yusufi Nov 14 '16 at 09:23
  • I want to know one thing that if a user chooses a size and color of a shoes and that is not in the database show what would be the sql query about it I am confused – Owaiz Yusufi Nov 16 '16 at 10:01
  • Your users will not be able to choose a size/colour combination that does not exist, because you will only be presenting the options that /do/ exist – Stuart Nov 16 '16 at 16:00
0

I think you sould create a new table like "type_product" to add the type of each product and put all your product in the same table

Frankich
  • 842
  • 9
  • 19