Jump to content

table help


kylewirth

Recommended Posts

here is how my comment table is setup.

 

id hashid1 hashid2

1 comment1 NULL

2 comment2   NULL

3 comment3 NULL

4 comment4 NULL

4       comment1

 

once someone creates a new thread, a new hashid3 column will be added.

 

the problem i have is that once a new hashid column is created, all of the rows are filled with null. if someone comments on the second topic (hashid2) it starts on id=5, not 1. How can i have the table not fill up will null values and have new comments start at id=1

Link to comment
Share on other sites

are you talking about a setup like this:

 

id  comments_column   

1    comment1

2    comment1

1    comment2

1    comment3

1    comment4

 

and then sort through to find. what if there are 100's of comments and 100's of topics?

 

or like this...

 

id    comment1_column      comment2_column

1    comment1                    comment2

2    comment1                    comment2

3    comment1                    comment2

4    comment1                    comment2

 

is this one even possible?

Link to comment
Share on other sites

You shouldn't need to alter your tables when a new thread or comment is added. You should set up two tables which are called threads, and comments.  The basic table structure would be

 

Threads

----------

thread_id auto_increment

thread_title

thread_poster

thread_body

 

Comments

-------------

comment_id auto_increment

thread_id

comment_poster

comment_body

 

When you add a thread you insert it into the threads table. All comments to that thread will go into the comments table. You link the comment to the thread by inserting the threads id into the thread_id column within the comments table. The query you'd use to get all comments associated with the thread would be

SELECT comment_title, comment_body, comment_author FROM comments WHERE thread_id='$thread_id'

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.