View Full Version : Working out when a week is?
Decode
30-08-2008, 07:56 PM
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?
Hypertext
30-08-2008, 09:10 PM
Why not just do it with MySQL, and then use MySQL Datetime and query like
<?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
?>
Stepheen
30-08-2008, 09:36 PM
*removed*
Edited by Invent (Forum Moderator): Please don't be rude.
Hypertext
30-08-2008, 09:38 PM
Stop bringing arguments into threads! I could yawn and it would be more controversial on this forum than McCain.
Agnostic Bear
31-08-2008, 07:20 AM
Why not just do it with MySQL, and then use MySQL Datetime and query like
<?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?
$query = mysql_num_rows( mysql_query( 'SELECT `time` FROM `weekviews` WHERE `time` <= \'' . time() - 604800 . '\'' ) );
if( $query !== 0 )
{
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
Hypertext
31-08-2008, 04:59 PM
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.
Decode
31-08-2008, 05:02 PM
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.
Want to hide these adverts? Register an account for free!
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.