嗨,
我有一个由用户创建的步骤列表,在这个列表中我有多个类别。
例如。
<ul id="thelist">
<li class="a">step a1</li>
<li class="a">step a2</li>
<li class="b">step b1</li>
<li class="c">step c1</li>
</ul>
我如何将这些信息存储在数据库中。
我现在尝试的是:
User_Id -> created by User
list_Id -> Unique Id of the list
List_step_a -> matched by list Id
list_step_b -> Matched by List Id
List_step_c -> Matched by List ID
那么我应该使用多个表吗 例如:
table_list_id
list_step_a
list_step_b
List_step_c
或者是否有更好的方法将列表存储在数据库中,以便我更容易提取。
如有任何帮助,我们将不胜感激。 有人至少能指出我正确的方向吗?
P.S 对英语感到抱歉。
其他信息: 我已经设法在 XML 中创建此信息。是否有替代方法可以在数据库上加载 XML 文件 UserSpecific。
我也尝试在 Cakephp 中创建它。
最佳答案
我会将其分成 2 个表(不包括给定要求的 users 表)
CREATE TABLE lists (
`id` INT(11) PRIMARY KEY,
`user_id` INT(11) // or whatever it is in the users table
`name` VARCHAR(255) // the name of the list
);
CREATE TABLE list_items (
`id` INT(11) PRIMARY KEY,
`list_id` INT(11) // links a list item to a list
`name` // name of the list item
);
通过正确的关系将这些模型连接起来将为您提供用户创建的列表以及该列表中的所有项目。希望这会有所帮助。
关于mysql - 数据库中的多个项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5876320/