Page is a not externally linkable
- Code, Content, and Presentation
-- Databases
---- page view stats - is this way too wasting?


ernest1b - 10:53 am on Oct 17, 2010 (gmt 0)


I need to show statistics per:
7 days
1 month
1 year

When user visit the page, function check if this date is already in database. If it is, it update field views+1, else create (INSERT INTO pageviews (pageId, pageviews, date) VALUES ('$pageId', 1, '".time()."').

I am wondering if the following method to wasting for database or is ok?
$minDate=time() - (365 * 24 * 60 * 60);
$maxDate=time();
$yearStat=$db->get_results("SELECT * FROM page_year_stat WHERE date>$minDate AND date<$maxDate");
$pageViews=0;
if($yearStat){
foreach($yearStat as $date=>$value){
$pageViews=$pageViews+$value;
}
}


2nd option
Or would be better to save data for each month, and than just cut some days from previous month and take some days from current month (because 1 month means [30 days - now] and not [1st day of the current month -current day of the current month]).


Thread source:: http://www.webmasterworld.com/databases_sql_mysql/4217905.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com