简体   繁体   中英

Echo number of comments on an article and add a edit / delete button to each comment?

the things is quite simple i guess for some of you, but for me it is quite hard since i`ma beginner. :) i'm developing a website template on localhost and i want to integrate a blog page on it. i succesfully added the form and linked it to the database for the comments to show on the desired article page. i now need to add a delete and edit button for each comment that can be accessed only by the user who posted it and the admin, and a link that shows how many comments are in the article. Can someone give me at least a hint ?:)

Ty in advance!

this is the code i have so far...apparently i cannot post images here.

http://postimg.org/image/g3u6vrxm3/

Actually you are correct about one thing... it is quite simple.

You will first need to check each comment to find out who the owner of that comment is. Then compare the two bits of information in an "IF" statement.

IF they match OR the user is an "Admin" THEN... show the edit link.

Somewhere inside your code block for the comment put something like this...

<div id="mycommentblock"><?php echo $rows['comment'] ?>
<?php // sql query to find out who the owner of this comment is
// like "SELECT * FROM commenttable WHERE id=$rows['id']"
if((isset($_SESSION['userid']) && $_SESSION['userid'] == '$row_commentOwner['id']') || $_SESSION['usergroup'] == 'Admin') { ?>&nbsp;&nbsp;<a href="editcomment.php?id=<?php echo $rows['id'] ?>">edit</a>&nbsp;<a href="deletecomment.php?id=<?php echo $rows['id'] ?>">delete</a><?php } ?>
</div>

Happy Coding !

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM