开发者

DBMS design for ads like website

I don't know how to design the dbms for the following requirement:

for an advertisement-like website there are a bunch of categories.

Every category has optional subcategories. Each subcategory may have optional subcategories ... and so on. Depending on each category (the user has selected to search for) there will be search criteria which are applicable only to this category, for example:

if the user has chosen the category Autos there will be the following search criteria: make, model,first registration, fuel type, but if she chooses the category Flats there will be the 开发者_如何学编程following search criteria: 2 bedrooms,3 bedrooms, private, agency .

I hope i explained it as simple as possible.


This means handling hierarchical data so there are many models to choose from, each one with it's limitations and advantages.

I would recommend reading http://articles.sitepoint.com/article/hierarchical-data-database before actually starting to design your schema. For my projects i've used the adjacency list approach because it's simpler to understand, but when you need to query it everything becomes difficult so maybe a nested set would be better.

MySql seems to recommend nested set http://mikehillyer.com/articles/managing-hierarchical-data-in-mysql/


table ad  [ad_id, category_id, {other fields}]
table category [category_id, name, parent_category_id(default=0)]

any category can have a parent category so you can shell them forever every ad has a starting category, if that category has children, then get those, if they have children then get those ad infinitum

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜