SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Addict
    Join Date
    Sep 2006
    Posts
    238
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    showing number of new posts

    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?

  2. #2
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What is the criateria for counting a comment as a new? Comment status? The try something like this:
    Code sql:
    $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";
    }
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  3. #3
    SitePoint Addict
    Join Date
    Sep 2006
    Posts
    238
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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?

  4. #4
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Show us the comment table structure if you have the field for that?
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  5. #5
    SitePoint Addict
    Join Date
    Sep 2006
    Posts
    238
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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)

  6. #6
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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'.
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  7. #7
    SitePoint Addict
    Join Date
    Sep 2006
    Posts
    238
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  8. #8
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Jaynesh View Post
    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.
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  9. #9
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    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?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •