SitePoint Sponsor

User Tag List

Results 1 to 1 of 1
  1. #1
    SitePoint Member
    Join Date
    Dec 2013
    0 Post(s)
    0 Thread(s)

    Separate comment sections

    Hello, Im making a php site and currently have one comment section that has like buttons and thus ranks comments in order of date and likes. However I want to have four different comment sections for different topics like how this forum works. I have a table in my phpadmin database that has sentiment and date, for my idea to work will i need another row perhaps called category to select comments from a certain category and apply these thanks.

    below is the code which deals with user ids and date/time stamps.
    Code PHP:
    $comment = clean_string($db_server, $_POST['comment']); 
     if($comment != ""){ 
     $query = "INSERT INTO comments (userID, comment) VALUES (" . $_SESSION['userID'] . ", '$comment')"; 
     mysqli_query($db_server, $query) or 
    	die("Insert failed: " . mysqli_error($db_server) ); 
     	$str_message = "Thanks for your comment!"; 
    //Create comments with or without submission
     $query = "SELECT comments.commDate, comments.ID, comments.userID, 
    comments.comment, comments.sentiment, users.username FROM comments JOIN users ON 
    comments.userID = users.ID ORDER BY sentiment DESC";
     $result = mysqli_query($db_server, $query); 
     if (!$result) die("Database access failed: " . mysqli_error($db_server) ); 
     while($row = mysqli_fetch_array($result)){ 
     $str_comments .= "<p><em>" . $row['username'] . ": (" . $row['commDate'] . ")</em><br /> " .$row['comment'] ." (" . $row['sentiment'] . ") "; 
     if(!isset($_SESSION["liked_" . $row['ID']])){ 
     $str_comments.= "<a href=\"likeprocess.php?likeid=" . $row['ID'] . "\"> This is a good present </a></p><hr />";
     $str_comments .= "liked<hr />"; 

    of course below this i have echo results and message, i haven't included them as they are not the problem.

    Once again, thanks
    Last edited by Mittineague; Dec 22, 2013 at 00:21. Reason: reformatting bbcode tags

Tags for this Thread


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts