Featured post
php - Finding the first and last days of each month in the period of time -
i have task make website article stats based on database results. need calculate amount of articles added monthly , pass these results javascript stats function.
the first i'm doing finding entire period in articles have been added:
select min(date) startdate articles limit 1 select max(date) enddate articles limit 1 now have period starts $startdate , ends $enddate. these variables unix timestamps in database. column date in database unix timestamp.
next, should find amount of articles have been added in each month doing query in foreach loop like:
select count(id) total articles date > ".$startmonth." , date < ".$endmonth but make need find first , last days of each month in period. , stucked @ moment. please can please suggest me how find these first , last days array. think should make strtotime("+1 month",$date) in while loop until $startdate equals $enddate. in advance.
upd. there total 46 articles in database. willing have results grouped month:
select date, count(id) total `articles` `author`=$author group date_format(date, '%y-%m') results: month posts 11-2010 13 12-2010 33
it seems can achieve using group by, like
select date_format(`date`, '%y-%m'), count(id) total articles group date_format(`date`, '%y-%m'); and not need date boundaries ...
- Get link
- X
- Other Apps
Comments
Post a Comment