Jump to content

[SOLVED] Write a Comment Mysql


TheFilmGod

Recommended Posts

So we all seen it - write a comment feature in news stories. Now how do I program that in mysql? The structure...???

 

One possibility is to have a table for everypage and each new entry would be a comment corresponding to that comment. Is there a better way to do this? Without creating too many tables?

 

I was thinking on the lines of having a huge table with all the comments and have comments with there IDs and have them bring up the appropriate comment by the id. Is that a good idea?

Link to comment
https://forums.phpfreaks.com/topic/61127-solved-write-a-comment-mysql/
Share on other sites

well the way i have it is that i have two tables..a news and comments table...each news article is assigned an auto incremented number for an id. Then when u post a comment on an article(which now has its own id) a column called newsid is then inserted with the id of the article...so then when displaying the comments for the article do SELECT * FROM comments WHERE newid=$id. $id would be a GET from the url...

I would do it something like this:

 

table news_stories:

id | page_id | author_id | title | story

 

table news_comments:

id | news_id | author_id | comment

 

So a page could be in the URL:

news.php?page=1

news.php?page=2

...etc

 

Then $_GET['page'] sets up the query to select the news articles on that page and for comments you would do select all the comments where the news_id = id (the news article id)

 

Just brief but I hope that makes sense. :P 2 tables seems sufficient. (I would avoid a table for each page).

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.