Feeling Dirty After So Much SQL

Meta: April 28th 2009 // CakePHP // 12 views

What this does is go through my Apache log in my MySQL DB and calculate unique hits, overall hits, amount of bandwidth used per month, and only for the past 3 months! Making sure each month begins and ends on the first and last day of the month, not using timestamps from the current date! Phew. Brain hurts.

$size = $this->Show->Episode->Log->find('all', array('conditions'=>array('Log.filecode'=>$filecodes,'UNIX_TIMESTAMP(`timestamp`) 
BETWEEN 
UNIX_TIMESTAMP(DATE_FORMAT(LAST_DAY(DATE_SUB(NOW(), INTERVAL 2 MONTH)), \'%Y%m01000000\')) 
AND 
UNIX_TIMESTAMP(DATE_FORMAT(LAST_DAY(NOW()), \'%Y%m%d235959\'))'), 'group'=>array('YEAR(timestamp)', 'MONTH(timestamp)'), 
'fields'=>array('Log.*', 'UNIX_TIMESTAMP(timestamp) as timestamp', 'SUM(Log.size) AS size', 'COUNT(*) as hits', 'COUNT(distinct ip) as uhits'), 'order'=>array('timestamp DESC')));

Tags: ,

WeDecal.com

Postscript: Leave A Comment // Subscribe (RSS Feed)

Want To Be Heard? Comment Here!

// I Love Comments, Especially Nice Ones

Who Are You?

Your Email Address

Your Website

:D :) :o :eek: :( :lol: :wink: :arrow: :idea: :?: :!: :evil: :p

You can follow any responses to this entry via its RSS comments feed. You may also leave a trackback by clicking this link.