Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Aug 2011
    Posts
    134
    Thanks
    20
    Thanked 0 Times in 0 Posts

    display result of last 30 days

    I have a post table that has some of these fields:
    i want to query the number of posts that happened in the last 30 days and display the date.i.e display posts that happened on each date and the also display the date.
    EG:
    NO DATE
    POSTS 10 1/9/2011
    POSTS 20 31/8/2011

    i know i can do a select postid and then do a mysql_num_rows to get the number of posts. But I am not sure how to get the result of last 30 days and display that date. Here is my table structure
    postid username userid title dateline
    1 test 3 member 1186945212
    3 tester 5 JM 1187106827

  • #2
    Senior Coder Rowsdower!'s Avatar
    Join Date
    Oct 2008
    Location
    Some say it's everything.
    Posts
    2,027
    Thanks
    5
    Thanked 397 Times in 390 Posts
    Just calculate the timestamp that would be from 30 days ago (use strtotime() for this) and search for all entries greater than that:

    PHP Code:
    $limit strtotime("-1 month");
    $query="SELECT * FROM table WHERE timestamp > $limit"
    I am guessing at your names for the table and for the timestamp column. Replace those with the correct names and this should work.
    The object of opening the mind, as of opening the mouth, is to shut it again on something solid. –G.K. Chesterton
    See Mediocrity in its Infancy
    It's usually a good idea to start out with this at the VERY TOP of your CSS: * {border:0;margin:0;padding:0;}
    Seek and you shall find... basically:
    validate your markup | view your page cross-browser/cross-platform | free web tutorials | free hosting


  •  

    Tags for this Thread

    Posting Permissions

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