php - count mysql values for the week and then start count again from monday? -


i have count query counts how many times user has viewed users profile. counts rows in table, wondering if there way in php use calculation says count rows in table 'ptb_profile_views' monday sunday , start 0 again on following monday , count values week , not include counts previous week, im not sure possible thought because need time of memory aspect behind it,

the other option wondering whether theres mysql statement can add every sunday @ 00:00am delete ptb_profile_views , start fresh monday.

can please me sort of solution, thanks

my table looks like:

id   |   profile_id   |   viewed_id  1           4                 8 2           5                 6 

mysql

function check_profile_views() {             global $connection;             global $_session;             $query = "select count(distinct profile_id) totalcount ptb_profile_views viewed_profile_id=".$_session['user_id']." , profile_id!='-1'";             $check_profile_views_set = mysql_query($query, $connection);             confirm_query($check_profile_views_set);             return $check_profile_views_set;                 } 

php

 <?     $check_profile_views_set = check_profile_views();     while ($views = mysql_fetch_array($check_profile_views_set)) {      echo"".$views['totalcount'].""; } ?>  

you can filter day-of-week, week-of-year, e.g.

select count(*), year(datefield), week_of_year(datefield) yourtable group year(datefield), week_of_year(datefield) 

the deletion logic similar. delete records in year have week-of-year earlier "this week", , delete records previous years:

delete yourtable (year(datefield) < year(now()))    or (year(datefield) = year(now()) , (week_of_year(datefield) < week_of_year(now())) 

Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -