Hello
I am working on a php/mysql website which allows users to make posts, and other users to comment on them.
How can I create a notification that displays the number of new comments on a post?
Hello
I am working on a php/mysql website which allows users to make posts, and other users to comment on them.
How can I create a notification that displays the number of new comments on a post?
What is the criateria for counting a comment as a new? Comment status? The try something like this:
$postid = isset($_GET['postid']) ? mysql_real_escape_string($_GET['postid']) : 0;
if(!empty($postid)){
$sql = "SELECT COUNT(id) as total_comemnts FROM tbl_comments WHERE post_id=$postid AND comment_status=0";
}
Hi thank you for you response.
I want the comment to be marked as new until the user views the comment, how do I go about doing that?
Show us the comment table structure if you have the field for that?
Hi
This is the structure:
id
post_id (the post which is being commented on)
user_id (the user commenting on the post)
comment (the comment)
So you have to add a field/column which indicates the status of the comment. It can be boolean type having true/false or 0/1.
0 = Not viewed yet.
1 = Viewed.
So add a field:
comment_status tinyint(4)
And insert 0 value in it when adding/inserting new comments. And use the SQL I have provided above to query the number of new comments. When a comment is viewed then update the field/column comment_status with the value ‘1’.
Hi I am not sure if this would make sense, as each comment isn’t inserted seperate for each user. So if the comment status is 1, it would be 1 for all users.
I don’t know what you mean but seeing your table structure, each comment will be inserted as a separate comment for the post. Otherwise why should the post_id and user_id are needed in the table.
Lets see if I grok this.
You are the original poster and you make a post at 1:00 pm.
Lets say for arguments sake you get a comment made every hour on the hour after that, starting at 2.00pm
So you go back at 3:15pm and you see “you have 2 new replies”.
You then go away and come back at 6.15pm and you see a message “you have 3 new replies”.
Is that what you are after?