TheFilmGod Posted July 21, 2007 Share Posted July 21, 2007 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? Quote Link to comment Share on other sites More sharing options...
L Posted July 21, 2007 Share Posted July 21, 2007 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... Quote Link to comment Share on other sites More sharing options...
Mutley Posted July 21, 2007 Share Posted July 21, 2007 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. 2 tables seems sufficient. (I would avoid a table for each page). Quote Link to comment Share on other sites More sharing options...
TheFilmGod Posted July 21, 2007 Author Share Posted July 21, 2007 Thank you for your help. This now makes a lot of sense. I guess my way would be too complicated! Thanks! Quote Link to comment Share on other sites More sharing options...
AndyB Posted July 21, 2007 Share Posted July 21, 2007 http://www.digitalmidget.com/php_noob/comment.php Mine might give you some ideas. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.