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 Link to comment https://forums.phpfreaks.com/topic/266125-advice-on-creating-a-comment-addon/ 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 Link to comment https://forums.phpfreaks.com/topic/266125-advice-on-creating-a-comment-addon/#findComment-1363751 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 Link to comment https://forums.phpfreaks.com/topic/266125-advice-on-creating-a-comment-addon/#findComment-1363779 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 Link to comment https://forums.phpfreaks.com/topic/266125-advice-on-creating-a-comment-addon/#findComment-1363972 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 Link to comment https://forums.phpfreaks.com/topic/266125-advice-on-creating-a-comment-addon/#findComment-1364016 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. Link to comment https://forums.phpfreaks.com/topic/266125-advice-on-creating-a-comment-addon/#findComment-1364018 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.