我为我的网站创建了一个用户评论部分,并在网页上显示评论以及报告滥用行为的标记。它在数据库comment_id,用户名,电子邮件,评论和post_id中有五列用户正在评论。以下是我用来显示数据库中的注释的PHP代码:
try
{
$result = $conn->prepare("SELECT * FROM user_comment WHERE post_id ='$post_id'");
$result->execute();
$count=$result->rowCount();
$def_com = $count;
if(!$count)
{
$def_com = "Be the First one to comment.";
}
else{
$data = array();
while ($data = $result->fetch())
{
$datas[] = $data;
}
foreach ($datas as $data)
{
echo " <div class='col-md-12 com-row' >
<img src='img/user.png' style='height:60px;width:60px;align:left'>"
." <p style='margin-left:80px; margin-top:-50px'> b>".$data['user_name']."</b> ".
$data['time']." ".$data['comment_id']."<br>".$data['comment']. "</p>
<a class='flagBtn smGlobalBtn flagdiv' name='report-comment' href='reportabuse.php'></a><br><br>";
}
它正常显示给定帖子的所有评论。我在会话变量中有post id并在select语句中使用它。
我的问题是,当我点击标志按钮时,我希望将评论ID传递给reportabuse.php页面。这个id应该对应于使用点击了标志按钮的注释。
如何获得它我已经尝试了会话变量,但它传递的最后一条评论的ID与用户点击的评论标志无关。
我尝试从帖子页面过去报告滥用页面的任何评论信息显示最后评论的信息只与点击哪个评论的标志按钮无关。我只需要点击其标记按钮的评论信息。
我尝试使用表单来显示评论,但没有用,问题仍然存在。
答案 0 :(得分:0)
为什么不将id作为参数传递给a href的URL,例如href ='reportabuse.php?cid = 1234' 在reportabuse.php页面上为$ _GET [“cid”]插入了url中传递的id。
有关$ _GET http://php.net/manual/en/reserved.variables.get.php
的更多信息