Reputation: 171
HI,
I have a list of steps created by a user, in this list i have multiple categories.
eg.
<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>
how would i store this information in a database.
what i trying right now is:
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
so should i use multiple tables eg:
table_list_id
list_step_a
list_step_b
List_step_c
OR is there a better way to store the list in the database so its easier for me to pull out.
Any help would be appreciated. Can somebody point me the right direction atleast.
P.S sorry about the english.
other information: I have managed to create this information IN XML.is there an alternative where i can load the XML file UserSpecific on the database.
also I am trying to create this in Cakephp.
Upvotes: 0
Views: 98
Reputation: 1437
I would break it up into 2 tables (excluding the users table which is a given requirement)
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
);
Joining these models up with the correct relationships will give you the lists created by the user and all of the items within that list. Hope this helps.
Upvotes: 2
Reputation: 11574
Create a table for the "steps":
CREATE TABLE steps (
`id` INT(11) PRIMARY KEY,
`user_id` INT(11) [or CHAR(36)],
`order` INT(11),
`name` VARCHAR(10)
);
Then populate this with the steps. Then when you need the steps, just pull them back out:
$this->Step->find('list', array('conditions' => array('Step.user_id' = $user_id), 'order' => array('Step.order')));
Display them in the order they come out.
Upvotes: 0