Results 1 to 7 of 7
  1. #1
    Join Date
    Dec 2006
    Posts
    3,970
    Tokens
    0

    Latest Awards:

    Default Working out when a week is?

    On my site there is a table for weekly views, but it needs to be reset each week. I don't want to do it manualy every week and my server doesn't support cron (I think thats what its called).

    So is there any way to detect if its been a week since the table rows have been reset back to 0?
    Lets set the stage on fire, and hollywood will be jealous.

  2. #2
    Join Date
    Sep 2006
    Location
    Evanston, Illinois.
    Posts
    2,361
    Tokens
    0

    Latest Awards:

    Default

    Why not just do it with MySQL, and then use MySQL Datetime and query like
    PHP Code:
    <?php
    $one_week_ago 
    date('Y-m-d H:i:s'time()-(60*50*24*7));
    $now date('Y-m-d H:i:s');
    $query mysql_query("SELECT SUM(`views`) AS `viewsThisWeek` FROM `views` WHERE `date` BETWEEN '{$one_week_ago}' AND '{$now}'");
    // insert a row on view for more detailed information, such as peak times etc
    echo 'Views this week' $query['viewsThisWeek'];
    //untested 
    ?>
    How could this hapen to meeeeeeeeeeeeeee?lol.

  3. #3
    Join Date
    May 2008
    Location
    Birmingham
    Posts
    307
    Tokens
    0

    Default

    *removed*

    Edited by Invent (Forum Moderator): Please don't be rude.
    Last edited by Invent; 30-08-2008 at 09:50 PM.

  4. #4
    Join Date
    Sep 2006
    Location
    Evanston, Illinois.
    Posts
    2,361
    Tokens
    0

    Latest Awards:

    Default

    Stop bringing arguments into threads! I could yawn and it would be more controversial on this forum than McCain.
    How could this hapen to meeeeeeeeeeeeeee?lol.

  5. #5
    Join Date
    Oct 2006
    Location
    Peterborough, UK
    Posts
    3,855
    Tokens
    216

    Latest Awards:

    Default

    Quote Originally Posted by Hypertext View Post
    Why not just do it with MySQL, and then use MySQL Datetime and query like
    PHP Code:
    <?php
    $one_week_ago 
    date('Y-m-d H:i:s'time()-(60*50*24*7));
    $now date('Y-m-d H:i:s');
    $query mysql_query("SELECT SUM(`views`) AS `viewsThisWeek` FROM `views` WHERE `date` BETWEEN '{$one_week_ago}' AND '{$now}'");
    // insert a row on view for more detailed information, such as peak times etc
    echo 'Views this week' $query['viewsThisWeek'];
    //untested 
    ?>
    Can you not read, seriously?

    PHP Code:
    $query mysql_num_rowsmysql_query'SELECT `time` FROM `weekviews` WHERE `time` <= \'' time() - 604800 '\'' ) );
    if( 
    $query !== )
    {
        
    mysql_query'TRUNCATE TABLE `weekviews`' );

    You'll need a time field on the table, either use time() in php or just UNIX_TIMESTAMP() in mysql
    Last edited by Jewish Bear; 31-08-2008 at 07:22 AM.


    visit my internet web site on the internet
    http://dong.engineer/
    it is just videos by bill wurtz videos you have been warned

  6. #6
    Join Date
    Sep 2006
    Location
    Evanston, Illinois.
    Posts
    2,361
    Tokens
    0

    Latest Awards:

    Default

    I was just giving him a better way to do stats... I don't know why you wouldn't want more info than a count, and I definitely don't know why you'd want to destroy valuable data.. such as statistics.
    How could this hapen to meeeeeeeeeeeeeee?lol.

  7. #7
    Join Date
    Dec 2006
    Posts
    3,970
    Tokens
    0

    Latest Awards:

    Default

    Ive found a way arround it now, my table was like

    |--PAGE ID---|--VIEWS--|---VIEWSINWEEK--|
    |----1-------|---288----|------48-----------|
    |----2-------|---234----|------15-----------|

    So I have just added a text file which has the last time() that the views col was emptyed. Then when a page is viewed it checks to see if its over 1 week.

    Thanks for you help anyway.
    Lets set the stage on fire, and hollywood will be jealous.

Posting Permissions

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