Im trying to Hide a comments that are not releated with the post above, the problem is that I have a database with all comments, and they are present in every post that I add... I'm trying to add a data-ID for every comments and trying to create a PHP "if" inside a generator post that if doesn't match doesn't show, but I think that i'm going to complicate myself, please help me:
this is a PHP function that create a comment and as you can see I added a data-POSTER that rappresent the ID of the post:
function createCommentRow($data,$utenteloggato) {
global $conn;
if ($utenteloggato == $data['userID']) {
$response = '
<div class="comment" data-postER="'.$data['postID'].'" >
<div class="user">'.$data['name'].' <span class="time">'.$data['createdOn'].'</span></div>
<div class="userComment" >'.$data['comment'].'</div>
<div class="reply"><a href="javascript:void(0)" data-commentID="'.$data['id'].'" onclick="reply(this)">REPLY</a></div>
<div class="replies">
<a id="option1"
data-id="'.$data['id'].'"
data-option="'.$data['tipo'].'"
href="javascript:void(0)"
onclick="goDoSomething(this);">
Delete
</a> ' ;
}
else
{
$response = '
<div class="comment" data-postER"'.$data['postID'].'" >
<div class="user">'.$data['name'].' <span class="time">'.$data['createdOn'].'</span></div>
<div class="userComment" data-postID="'.$data['postID'].'">'.$data['comment'].'</div>
<div class="reply"><a href="javascript:void(0)" data-commentID="'.$data['id'].'" onclick="reply(this)">REPLY</a></div>
<div class="replies">
' ;
}
$sql = $conn->query("SELECT replies.id, name, comment, tipo, DATE_FORMAT(replies.createdOn, '%e/%c/%Y %T') AS createdOn, userID, postID FROM replies INNER JOIN users ON replies.userID = users.id WHERE replies.commentID = '".$data['id']."' ORDER BY replies.id DESC LIMIT 1");
while($data = $sql->fetch_assoc())
$response .= createCommentRow($data,$utenteloggato);
$response .= '
</div>
</div>
';
return $response;
}
inside ad another php I show all the post from database table "post", everything work fine, but inside this div where the comments go to display:
<div class="userComments" data-postID="'.$data['id'].'" > </div>
I want put a IF condition that if the value of data-postER from the comments doesn't much with the data-postID from class="userComments" it doesn't show up. Thanks to everybody