2012-08-11 140 views
1

我正在爲許多產品將存儲的珠寶網站設計數據庫。在設計表格時,我粘住了產品的屬性。我的問題是如何在數據庫中存儲產品屬性和子屬性等。如何設計數據庫以將屬性屬性存儲到數據庫中

到現在爲止我已經爲產品3個表和屬性 -

  1. tbl_attribute

    Structure: attribute_id*, attribute_name 
    
  2. tbl_products

    Structure: product_id*, category_id(FK), product_name, seo, description, metatags, length, width, height, weight, image, status 
    
  3. tbl_products_attribute

    Structure: product_id(fk), attribute_id(fk), value 
    

我有一個情況假設項鍊具有5個結石(石是屬性),並且每個石頭已經以下子屬性 1.石名稱 2.石頭顏色 3.石治療方法 4斯通Clearity 5.石像形態 6.石價格

等等等等....和我有一樣這麼多的屬性,所以可以請你幫我如何設計的TA適合這些屬性。

取決於該屬性,我必須在前端搜索(FILTER ||分面搜索)產品。

像:www.firemountaingems.com


詳細的屬性和子屬性列表:

Alphabatical 
Availability (Sold Individualy, Sold in Bulk) 
Birth Stone 
Brands 
Color (red, green, blue) 
Design Type 
Gender (Male, Female) 
Images 
Karat (18k, 22k, 24k) 
Link 
Make (Hand, Machine, Oxidised) 
Making Percent 
Material Type (Leather, Gemstone, etc) 
Metal Art 
Metal Stamp 
Metal Type (Gold, Silver, PLatinum etc) 
Model 
Name 
Price 
Purity 
Shapes (round, oval, emerald, diamond etc) 
Short Description 
Sides (single, both,) 
Size (small, big etc) 
Special Price 
Status 
Stone (Name, Color, Treated Method, Clearity, Shape, Price, Main Stone Color (Red, Pink, Green)) 
Stringing Material 
Warranty 
Wastage Percent 
Weight 
Wire - Wrapping Wire 

到現在我有搜索淨以及對堆棧溢出這麼多的教程和文章。

非常感謝您的幫助。

回答

1

在這種情況下,你不能提供像這樣創建表最好的方法是隻有1個產品表和1個屬性表,它們具有產品的所有屬性,但是具有列attribute_level和parent_id,其中parent_id引用同一表的ID 。

例子: 產品表:

ID | Name 
---------- 
1 | Necklace 


ID | ParentID | AttributeName | ProductID | AttributeLevel | AttributeDescription 
---------------------------------------------------------------------------------- 
1 |   | Stone   | 1   | 1    | stone description in general 
2 | 1  | StoneName  | 1   | 2    | Ruby 

通過這種方式,你可以一個表內作出屬性水平的hirerchy。

+0

親愛的Immam我明白你想要解釋什麼,這對我的情況非常有幫助,我喜歡它,但我又有一個查詢,我將如何根據屬性和子屬性搜索產品。我必須根據許多屬性過濾產品,例如類別,金屬,形狀,顏色,價格等。 – w3uiguru 2012-08-11 13:05:13

+0

@HappySingh我建議使用1表來保存所有級別的屬性(屬性,子屬性等)的信息,並將以ID作爲主鍵,然後爲其子屬性,該ID將設置在其parentID,它將工作。 – Elvin 2012-08-11 13:24:45

+0

假設您必須搜索具有黑色顏色的產品。現在,您在使用我的方法進行搜索查詢時看到了什麼問題,其中每個屬性都有其產品,並且鏈接到所有其父屬性具有parentid並且與子屬性相同。 – Elvin 2012-08-11 13:27:46

相關問題