2011-05-03 56 views
0

嗨,数据库中的多个项目

我有一个由用户创建的步骤列表,在此列表中我有多个类别。

例如。

​​

我该如何将这些信息存储在数据库中。

什么,我现在想的是:

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 

或是否有更好的方式来存储列表中的数据库中,以便其更容易为我拔出。

任何帮助,将不胜感激。 有人能指出我的正确方向吗?

对于英语感到抱歉。

其他信息: 我已经成功地在XML.is中创建了这个信息,在那里我可以加载数据库上的XML文件UserSpecific。

我也试图在Cakephp中创建它。

回答

0

的 “台阶” 创建表:

CREATE TABLE steps (
`id` INT(11) PRIMARY KEY, 
`user_id` INT(11) [or CHAR(36)], 
`order` INT(11), 
`name` VARCHAR(10) 
); 

然后与步骤填充此。然后当你需要的步骤,只需将他们拉回来:

$this->Step->find('list', array('conditions' => array('Step.user_id' = $user_id), 'order' => array('Step.order'))); 

按它们出来的顺序显示它们。

+0

谢谢。将尽快尝试。 – Vwake 2011-05-03 22:37:55

2

我将其拆分成2个表(不包括用户表,它是一个给定的要求)

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 
); 

加入这些模型与正确的关系,会给你的用户和所有创建的列表该列表中的项目。希望这可以帮助。