PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
$lastmonth = mktime(0,0,0,date("m")-1,1,date("Y"));
$lastmonth = date("m", $lastmonth);
$clicks_lm_sql = mysql_query("SELECT COUNT(*) FROM `tracking` WHERE MONTH(date)={$lastmonth} AND `advert_id`={$advert['id']}");
$clicks_lm = mysql_fetch_row($clicks_lm_sql);
echo $clicks_lm[0];
The problem is that if we are in january, wont it return results from the same year, rather than december of the previous year?
Do anybody have any idea how to get around this? The date field is in mysql date format, and ideally i'd like to keep it that way.
$lastmonth = mktime(0,0,0,date("m")-1,1,date("Y"));
$lastmonth = date("m", $lastmonth);
$clicks_lm_sql = mysql_query("SELECT COUNT(*) FROM `tracking` WHERE MONTH(date)={$lastmonth} AND `advert_id`={$advert['id']}");
$clicks_lm = mysql_fetch_row($clicks_lm_sql);
echo $clicks_lm[0];
The problem is that if we are in january, wont it return results from the same year, rather than december of the previous year?
Do anybody have any idea how to get around this? The date field is in mysql date format, and ideally i'd like to keep it that way.
If you want it to get it from the last month even it its Jan. do this:
On a related note, can anyone suggest a way to get DISTINCT month's from the database taking the year into account in a similar way?
This is on the same table.