Re: SQL/Query - get months with posts

2007-03-31 Thread d34db0lts
i have a similar question. i have two tables where table 'courses' hasMany 'students' and 'students' belongs to 'courses'. I want to be able to have a list of all the courses and count how many students there are (ex: english - 20 students, math - 35 students). I've been searching all over...Count

Re: SQL/Query - get months with posts

2007-03-08 Thread Jon Bennett
> SELECT DISTINCT YEAR(date) AS year, MONTH(date) AS month, count(id) AS > numb > FROM articles > GROUP BY YEAR(date), MONTH(date) > ORDER BY date DESC > > This way you get the results grouped by year, with each month and the > number of articles per month. Bam. thanks, that works perfectly jon

Re: SQL/Query - get months with posts

2007-03-08 Thread phirschybar
You could do a query like this: SELECT DISTINCT YEAR(date) AS year, MONTH(date) AS month, count(id) AS numb FROM articles GROUP BY YEAR(date), MONTH(date) ORDER BY date DESC This way you get the results grouped by year, with each month and the number of articles per month. Bam. On Mar 8, 7:25

Re: SQL/Query - get months with posts

2007-03-08 Thread hausburger
something like that? function getRange() { $q = " SELECT date_format(`date` , '%M %Y' ) AS month_year FROM posts WHERE active = '1' GROUP BY date_format(`date` , '%m-%Y' ) LIMIT 0, 12"; $result = $this->query($q); return $res

SQL/Query - get months with posts

2007-03-08 Thread Jon Bennett
hi, we have a blog app [http://www.webmarketingblog.co.uk/blog] and in the sidebar we want to have a list of months that have posts, eg: Febuary 2007 March 2007 ... etc etc any pointers on querying my model so I can get a list of months with active posts? many thanks, Jon -- jon bennett t