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
https://forums.phpfreaks.com/topic/212147-table-help/
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
https://forums.phpfreaks.com/topic/212147-table-help/#findComment-1105682
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
https://forums.phpfreaks.com/topic/212147-table-help/#findComment-1106151
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.