我有一个页面,显示所有用户发布的评论。在这里,我需要在当前登录用户发布的评论一侧显示删除链接,他也应该能够删除该评论(如Facebook,Orkut或任何Blogging网站)。我尝试过的示例代码是:
<?php
$user_id = 1;
$con = mysql_connect("localhost","root","root");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("blog", $con);
$result = mysql_query("SELECT * FROM replies");
while($row = mysql_fetch_array($result))
{
$replies = $row;
if($replies['poster_id' == $user_id]){
$delete = '<a href="#">Delete</a>';
}
echo $replies['poster_id']?></a> ¦ <?php echo $replies['reply_text']?> ¦ <?php echo $delete?></div>
<?php echo "<br />";
}
mysql_close($con);
?>
这里我给出了这里硬编码的user_id。 我得到的是,删除链接显示在所有评论上。我需要显示user_id的删除链接,仅显示“1”。 任何人都可以建议我得到解决方案......在此先感谢...
答案 0 :(得分:0)
<?php
if (isset($_GET['reply'],$_GET['where']))
$result=mysql_query("Delete FROM $replies WHERE entry_id = '$_GET['reply']'");
$username = $session->username;
$result=mysql_query("SELECT * FROM $replies WHERE entry_id = '$id' ORDER by reply_id DESC");
while ($i = mysql_fetch_array($result))
{
$replies = $i;
if ($replies['poster_id'] == $username){
$delete = '<a href="delete?where='.$id.'&reply='.$replies['reply_id'].'">Delete</a>';
}
?>
<div>
<div><a href="profiles/<?php echo $replies['poster_id']?>">
<?php echo $replies['poster_id']?></a> ¦ <?php echo $replies['post_time']?> ¦ <?php echo $delete?></div>
<div><?php echo $replies['reply_text']?></div>
</div><br/><br/>
<?
}
答案 1 :(得分:0)
我知道这有点老了,可能已经很好地照顾了,但是你忘记了;在$ delete之后
<?php echo $delete?>
应该是
<?php echo $delete; ?>