By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,948 Members | 1,975 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,948 IT Pros & Developers. It's quick & easy.

Display delete link near comments for that logged in users

P: 1
I have a page which shows the comments posted by all users. Here I need to show a delete link on the side of the comments posted by that current logged in user and he should be able to delete that comment too (like in Facebook, Orkut or any Blogging site). The sample code which I have tried is:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $user_id = 1;
  3. $con = mysql_connect("localhost","root","root");
  4. if (!$con)
  5.   {
  6.   die('Could not connect: ' . mysql_error());
  7.   }
  8.  
  9. mysql_select_db("blog", $con);
  10.  
  11. $result = mysql_query("SELECT * FROM replies");
  12.  
  13. while($row = mysql_fetch_array($result))
  14.   {
  15.   $replies = $row;
  16.   if($replies['poster_id' == $user_id]){
  17.       $delete = '<a href="#">Delete</a>';
  18.   }
  19.  
  20.   echo $replies['poster_id']?></a>&nbsp;&nbsp;<?php echo $replies['reply_text']?>&nbsp;&nbsp;  <?php echo $delete?></div>
  21.  
  22.   <?php echo "<br />";
  23.   }
  24.  
  25. mysql_close($con);
  26. ?> 
  27.  
Here I have given the user_id which is hardcoded here. What I got is, delete link is displayed on all comments. I need to display delete link for user_id with "1" only. Can anyone suggest me to get the solution...Thanks in Advance...
May 1 '11 #1
Share this Question
Share on Google+
1 Reply


100+
P: 1,059
try this
Expand|Select|Wrap|Line Numbers
  1. <a href='javascript:createDeleteRequest("<?=$replies['poster_id']?>")'>[&nbsp;Delete&nbsp;]</a>
  2.  
createDeleteRequest make this function to create delete request using ajax. after ajax return successful reply hide the row that displays text

after process success
May 1 '11 #2

Post your reply

Sign in to post your reply or Sign up for a free account.