Dexlin Posted July 23, 2012 Share Posted July 23, 2012 Hi all, I have created a site that i would like to add comments to the post. This is how i have done it so far. it calls on example.php?id=$id which gets the $id and puts it into the the query "SELECT * FROM table WHERE id=$id the fills the page with a title and body text This all works great but i was just wondering what would be the best way of creating the comments addon so when each requested post i.e example.php?id=$id is called it will display the title and body text as well as the comments for that post. Any help will be great. Thanks Quote Link to comment Share on other sites More sharing options...
xflawless Posted July 23, 2012 Share Posted July 23, 2012 I would suggest you to use JOIN in your query. SELECT columns FROM table_a JOIN table_b ON table_a.id = table_b.id Quote Link to comment Share on other sites More sharing options...
xyph Posted July 23, 2012 Share Posted July 23, 2012 Please provide us with your current table structure Quote Link to comment Share on other sites More sharing options...
Dexlin Posted July 24, 2012 Author Share Posted July 24, 2012 Hi xyph, There is id,title, description,body,category,posted columns at the moment but this may change but at the moment its just the ones i have said. Thanks Quote Link to comment Share on other sites More sharing options...
xyph Posted July 24, 2012 Share Posted July 24, 2012 Create a new table called comments. id, parent_id, body, posted_by, date, whatever else. id - Auto-increment primary ID parent_id - the 'id' column of the article the comment is attached to You can then get all of an articles comments using SELECT * FROM comments WHERE parent_id = $id ORDER BY date DESC Quote Link to comment Share on other sites More sharing options...
Dexlin Posted July 24, 2012 Author Share Posted July 24, 2012 Thank you very much i will give it a go. 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.