> Hi, i am writing a news management system in PHP, with comments, etc, and >i am wondering if theres a better way of structuring the tables to increase >speed and stability. > This is how i am structuring my tables: > > Table 1 (news) > ------------------------------ > ID > Date > Author > Title > News Text > > > Table 2 (comments) > -------------------------------- > ID > News ID (to which news it belongs to) > Date > Author > Comment text
Looks good! Though I would avoid "two word" columns: news_text news_id comment_text You *might* also want to record commenters' IP addresses so you can track down abusers not smart enough to hide that... Or require a vaild email before commenting, or... *SOME* sort of control on posting. Or, for a small site, perhaps add a field "approved" and only display approved comments. Or, just leave it "wide open" :-) Just some ideas to consider. > Everytime i want to show the comments on some news article, i have to do a >query to the whole table 2, selecting the entries that have the "news ID" >equal to the ID of the news i want. It works but is this ok for when i have >hundreds of news/comments later on? Wont it slow down things? Is there an >easier way for this news/comments script? There are two issues here: Q. How many comments can I have in SQL before MySQL pukes? A. Oh, a few million or so. Q. How many comments can I display on a single web page before HTTP is too slow? A. Maybe a dozen or so. Fortunately, you can use MySQL's LIMIT clause in your SQL and some navigation links/buttons to display the first 10 (next 10, next 10, ...) comments very easily. Search for "LIMIT" in the various MySQL/PHP sample code archives, and you'll find it fairly easy. -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php