Php 针对特定用户的表单中的问题显示按钮编辑

Php 针对特定用户的表单中的问题显示按钮编辑,php,mysql,Php,Mysql,我面临一个问题,显示编辑,删除按钮的评论,属于该用户,,,,这是我的代码,不明白问题在哪里,如何解决它(因为这样:编辑和删除按钮将显示所有的评论 $results = mysqli_query($c, "SELECT * from comments where idpub=".$_GET['com']."and iduser=".$_SESSION['id']); while ($rows = mysqli_fetch_assoc($results)) { ?> <?php ech

我面临一个问题,显示编辑,删除按钮的评论,属于该用户,,,,这是我的代码,不明白问题在哪里,如何解决它(因为这样:编辑和删除按钮将显示所有的评论

$results = mysqli_query($c, "SELECT * from comments where idpub=".$_GET['com']."and iduser=".$_SESSION['id']);
while ($rows = mysqli_fetch_assoc($results)) { 
?>
<?php echo $rows['username'];  ?>
<?php echo $rows['textcom']; ?>

      <a href="comment2.php?edit=<?php echo $rows['id']; ?>" class="edit_btn" >Edit</a>
<a href="pubf.php?del=<?php echo $rows['id']; ?>" class="del_btn">Delete</a>
<?php } ?>```
$results=mysqli\u query($c,“从注释中选择*,其中idpub=“.$\u GET['com']”和iduser=“.$\u SESSION['id']);
而($rows=mysqli_fetch_assoc($results)){
?>
```

您必须检查登录用户Id和添加该评论的评论用户Id。如果两个Id相同,则显示这些按钮

$results = mysqli_query($c, "SELECT * from comments where idpub=".$_GET['com']."and iduser=".$_SESSION['id']);
基于以上代码,我认为您正在获取存储在会话中的用户id的所有注释,因此它会在每个注释中显示编辑删除按钮。因此,您必须像下面这样更改代码

    $results = mysqli_query($c, "SELECT * from comments where idpub=".$_GET['com']);
while ($rows = mysqli_fetch_assoc($results)) { 
?>
<?php echo $rows['username'];  ?>
<?php echo $rows['textcom']; ?>
<?php if($_SESSION['id'] == $rows['userid']){ ?>


<a href="comment2.php?edit=<?php echo $rows['id']; ?>" class="edit_btn" 
>Edit</a>
<a href="pubf.php?del=<?php echo $rows['id']; ?>" class="del_btn">Delete</a>
<?php } }?>
$results=mysqli\u query($c,“从注释中选择*,其中idpub=“.$\u GET['com]”);
而($rows=mysqli_fetch_assoc($results)){
?>

Hello@yolo为什么你对我的答案投反对票,就像你接受我的答案一样。请投上一票。为什么你对我的答案投反对票?既然你接受了我的答案,你就必须投上一票。请投上一票。