我有一个"t_form“表和一个"t_attribute”表。看上去有点像下面。
表格
form_id | form_name | description
-----------------------------------
1 | Laptop | Possible attributes are Model, Screen Size, OS, Cd Player
2 | Mobile | Possible attributes are Model, OS
3 | Tablet | Possible attributes are Model, Screen size, OS属性表
attribute_id | attribute
------------------------
1 | Model
2 | Screen Size
3 | OS
4 | Cd PlayerForm_Attribute表
form_id | attribute_id
----------------------
1 | 1
1 | 2
1 | 3
1 | 4
2 | 2
2 | 2
3 | 2
3 | 2
3 | 2我将根据用户从数据库中选择的表单类型(笔记本电脑、移动台或平板电脑)生成HTML表单,如下所示(包含表单字段)。
笔记本电脑的:

For Mobile:

平板电脑:

问题:这里是我的问题。
滤波器:

请提供一个可行的解决方案和一些例子,以更好地了解我,并帮助我实现这一点。
发布于 2013-10-23 12:40:09
我想你可以买一张像
Form_Attribute_Values或项目
item_id | form_id | attribute_id | value
------------------------------------------------
1 | 1 | 1 | SuperLap
1 | 1 | 2 | 15
1 | 1 | 3 | MS-DOS 6
1 | 1 | 4 | Toshiba这样,您就可以查询输入的单个项,还可以通过表单、属性值或属性值进行筛选。
您的Form_Attribute表将非常方便地为特定表单生成表单(即当用户想要输入笔记本或移动电话时)。
Items表将是插入后存储项目的位置,或者是查询项目的位置。
您还可以在末尾添加一个时间戳列,以便在保存该项时存储;如果您的数据将由多个用户填充,则可以添加一个User_id列。如果您可以在存储中存储不可用的项,或者可以将可用性保存在单独的表中,那么也可以为可用性添加一个额外的列。
如果您可以从筛选表单中获得表单和属性id,则对屏幕大小为14-16的膝上型计算机的查询将如下所示:
SELECT item_id,
form_name,
attribute_name,
value
INNER JOIN form
ON item.form_id = form.form_id
INNER JOIN attribute
ON item.attribute_id = attribute.attribute_id
WHERE item_id IN (-- here I select for Laptop and Screen Size dimension
SELECT item_id
FROM item
WHERE form_id = 1
AND attribute_id = 2
AND item.value BETWEEN 14 and 16
)否则,您将需要更复杂的东西:
SELECT item_id
FROM item
INNER JOIN form
ON item.form_id = form.form_id
INNER JOIN attribute
ON item.attribute_id = attribute.attribute_id
WHERE item_id IN (-- here I select for Laptop and Screen Size dimension
SELECT item_id
FROM item
WHERE form_id = (-- but first I need the form_id
-- for Laptop
SELECT form_id
FROM form
WHERE form_name = 'Laptop')
AND attribute_id = (-- then I need the attribute_id
-- for Screen Size
SELECT attribute_id
FROM attribute
WHERE attribute_name = 'Screen Size')
AND item.value BETWEEN 14 and 16
)发布于 2013-10-23 18:05:58
假设您的属性正在增长,因为表单字段意味着,使用JASON格式将该记录存储到非关系DB (如MongoDB )中是很容易的。然后,您可以轻松地查询MongoDB Jason数据。
如果您使用的关系模型意味着上面的答案1将是最合适的。
https://stackoverflow.com/questions/19541119
复制相似问题