Web Hosting Talk







View Full Version : mySQL Question - Tables Setup


Aralanthir
11-04-2002, 07:09 PM
Hey all,

I'm pretty new to PHP/mySQL, and I've tried searching for the answer, but I can't seem to find it. It's probably incredibly simple, but I just don't know the keywords I'm supposed to be searching for.

I want to set up a database so that there is one table which stores information about a Story (storyid would be the primary key). Then, I want to link it to another table which stores the actual contents of the story in separate chapters (chapterid is the primary key). I read some tutorials on Normalization, and it *seems* to touch on what I'm looking for - but the chapterid is set to autoincrement, and I want it to reset for each separate story.

Right now, If the first story has 2 chapters, then the first chapter of the second story would start at 3.

What am I doing wrong? Am I supposed to create a new table for the chapters for each story?

If anyone knows of any tutorials that address my question, or can answer my question - I'd greatly appreciate any help! :)

jtrovato
11-04-2002, 07:56 PM
If I am understanding you. you are not doing anything wrong, you are right on key.

Table -> story (fields) -> storyid, name, etc
Table -> chapters (fields) -> chapterid, name, etc


You want a link from story table to the chapters table?

The id has to be different within each record. Maybe you can create another field just for the chapter numbers in the chapter's table. The ID is a key field and all key fields have to be different.

if you could send the structure of the two tables, I could help you out with some select and insert queries.

John

Aralanthir
11-04-2002, 08:03 PM
Thanks a lot for your suggestions! I knew it had to be something painfully obvious. Yeah, guess all I had to do was create another field for the actual chapter number. :)

I think I'll try and figure the stuff out myself from there. *crosses fingers* Hopefully, all will go well.

Thank you again for your help! :D I can't believe I never even thought of this.