Jump to content

Comments mySQL query help


HaLo2FrEeEk

Recommended Posts

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

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
  }
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.