Comments and Comments Text Box for Each Post

Hi Everyone;

i have a page where users can post and comment for each post.

Problem is when i click Comment button, the list of comments are shown only for one post which is on the first and also finding a way to list the comments related to the specific post.

The code to Show Posts are as follows:
showposts.php

[php]


<?php include 'connection.php'; ?>
<?php $sql = "SELECT * FROM posts ORDER BY id DESC"; $result = mysqli_query($connect, $sql);

while($row = mysqli_fetch_array($result)){
?>

PIX
<?php echo $row['username']?>
<?php echo $row['posteddate']?>
<?php echo $row['postedtime']?>
<?php echo $row['subject']?>
<?php echo $row['pubdata']?>
Like
Comment
Share <?php echo "
" . "Delete" . "
"?>
<?php /*WHERE postid='$postid'*/ $resultcmt=mysqli_query($connect, "SELECT * FROM comments ORDER BY cmtid DESC"); while($rowcmt=mysqli_fetch_array($resultcmt)){ ?>
PIX
<?php echo $rowcmt['comment'];?>

<?php }?>
Post

<?php } ?> [/php]

The code for Posting Comments are as follows;
commentpost.php
[php]

<?php include 'connection.php'; session_start(); $usrid = $_SESSION['loginid']; $usrname = $_SESSION['login_user']; //$postid = $_SESSION['postid']; if(isset($_POST['pid'])!=0){ $comment = $_POST['comments']; $postid = $_POST['pid']; mysqli_query($connect, "INSERT INTO comments (usrid,postid,comment) VALUE ('$usrid','$postid','$comment')"); header('location:house.php'); }else{ echo "ERROR"; } ?>[/php]

Below is the code i used to show and Hide comments ;

function showcomment() { var x = document.getElementById("comment"); if (x.style.display === "block") { x.style.display = "none"; } else { x.style.display = "block"; } }

Please Help


Sponsor our Newsletter | Privacy Policy | Terms of Service