Forum Moderators: coopster

Message Too Old, No Replies

Help with a loop

Whats wrong with my code?

         

nfs2

9:42 am on Mar 1, 2006 (gmt 0)

10+ Year Member



I have a blog set up, and i want members to be able to comment on it. I also want them to be able to delete their own comments if they want.

Here is my code so far {

$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>&nbsp;¦&nbsp;<?php echo $replies['post_time']?>&nbsp;¦&nbsp;<?php echo $delete?></div>

<div><?php echo $replies['reply_text']?></div>

</div><br/><br/>

<?
}

Now, heres the problem. The delete link should only show up on comments left by the logged in user. But the link shows up on ALL comments as long as the logged in user has left at least one comment. If the user has left no comments, no delete link is shown.

Any idea what im doing wrong?

Robber

10:22 am on Mar 1, 2006 (gmt 0)

10+ Year Member



Could it be that on one iteration you are setting $delete and then on subsequent iterations the $delete variable is already set from last time even if the post is not from the logged in user. You could check by adding an }else{$delete='';}

nfs2

10:53 am on Mar 1, 2006 (gmt 0)

10+ Year Member



I think thats exactly it.

I fixed it by replacing <?php echo $delete?> with the actual if statement.