HaLo2FrEeEk Posted April 21, 2007 Share Posted April 21, 2007 I am trying to grasp this concept in my head, but I'm not having much luck yet, unfortunately, I'm not ready to test yet witht he actual queries. Basically what I need is to have a database item with a certain id to identify and display it, then I want to have people be able to comment it. I can't really understand how I would have all the comments linked to this one item id, without having a lot of tables. The only thing I can think of is that I would have a table with the item information, then another table with comments, in the comment table, there would be item_id, then there would be comment_id, and the actual comment, along with poster information like IP address and name, and date. How would I do this, any help will be appreciated. Link to comment https://forums.phpfreaks.com/topic/47969-comments-mysql-query-help/ Share on other sites More sharing options...
AndyB Posted April 21, 2007 Share Posted April 21, 2007 Exactly as you describe it. If you want to, check out my comment script downloadable from www.digitalmidget.com/php_noob/comment.php Link to comment https://forums.phpfreaks.com/topic/47969-comments-mysql-query-help/#findComment-234392 Share on other sites More sharing options...
HaLo2FrEeEk Posted April 21, 2007 Author Share Posted April 21, 2007 Awesome, so basically I use that method, then to pull it out, I would do something like: <?php $id = $_GET['id']; // I'm using get so the id is displayed in the url, I want it that way. if(!isnumeric($id)) { die("You have entered a non compatible id"); // This should help with SQL Injection...I hope. } $query = "SELECT * FROM `comments` WHERE `id` = '".$id."' ORDER BY `comment_id` ASC"; $comments = mysql_query($query); while($info = mysql_fetch_array($comments)) { // echo comment code } ?> Link to comment https://forums.phpfreaks.com/topic/47969-comments-mysql-query-help/#findComment-234543 Share on other sites More sharing options...
AndyB Posted April 21, 2007 Share Posted April 21, 2007 Yes .. and you might want to add some pagination to cater for pages with many comments. Link to comment https://forums.phpfreaks.com/topic/47969-comments-mysql-query-help/#findComment-234654 Share on other sites More sharing options...
HaLo2FrEeEk Posted April 21, 2007 Author Share Posted April 21, 2007 I think I'll just do what I did with my frontpage of my site, http://claninfectionist.com, and limit the query to 5 or 10, unless the post variable view=all is set, when it is, it'll display em all. Link to comment https://forums.phpfreaks.com/topic/47969-comments-mysql-query-help/#findComment-234950 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.