jaynesh — 2011-12-15T07:23:47-05:00 — #1
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?
raju_gautam — 2011-12-15T07:51:08-05:00 — #2
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;
$sql = "SELECT COUNT(id) as total_comemnts FROM tbl_comments WHERE post_id=$postid AND comment_status=0";
jaynesh — 2011-12-15T08:01:31-05:00 — #3
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?
raju_gautam — 2011-12-15T08:58:26-05:00 — #4
Show us the comment table structure if you have the field for that?
jaynesh — 2011-12-15T15:57:04-05:00 — #5
This is the structure:
post_id (the post which is being commented on)
user_id (the user commenting on the post)
comment (the comment)
raju_gautam — 2011-12-16T00:37:23-05:00 — #6
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:
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'.
jaynesh — 2011-12-19T11:41:44-05:00 — #7
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.
raju_gautam — 2011-12-20T03:22:08-05:00 — #8
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.
cups — 2011-12-20T04:22:57-05:00 — #9
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?