I am building a blog archive navigation menu. Currently I run a query to get all the years and months. Then I loop through and run the following query to get all id’s and titles of that year/months blog posts:
SELECT `id`, `title`
FROM `news`
WHERE YEAR(`date`) = "2010" AND MONTH(`date`) = "03"
ORDER BY `date` DESC
After that, to count the amount of posts for that month I am running a very similar query:
SELECT COUNT(*) as `count`
FROM `news`
WHERE YEAR(`date`) = "2010" AND MONTH(`date`) = "03"
The year and month are dynamic of course.
Is there any way to avoid having to run two separate queries?
Thanks ahead of time!
You can count the rows via php after sending the first query (http://php.net/manual/en/function.mysql-num-rows.php)