Forum
Possible Bug in month_qty for Blog Archive
Hi
I have two distinct blog posts in the same month, but the month_qty count that is available in the months_month_link.html is returning the value 1, rather than the expected count of 2.
It seems the driving query is the following (which I found in PerchBlog_Posts.class) - note, this query contains the parameters as executed in my scenario...
SELECT DISTINCT
year(postDateTime) AS year,
month(postDateTime) AS month,
CONCAT(year(postDateTime),"-",month(postDateTime),"-01") AS postDateTime,
COUNT(*) AS month_qty
FROM perch3_blog_posts p
WHERE year(postDateTime) = '2017'
AND p.postStatus='Published'
AND p.postDateTime<='2017-06-08 08:20:00'
GROUP BY year, month, postDateTime
ORDER BY month DESC
I think the confusion / problem comes from using the column alias of postDateTime in this code CONCAT(year(postDateTime),"-",month(postDateTime),"-01") AS postDateTime
which is also in the Group By clause and is the same as a the actual table column name of postDateTime.
If I change the query to the following, the month_qty count is being correctly calculated as 2...
SELECT DISTINCT
year(postDateTime) AS year,
month(postDateTime) AS month,
CONCAT(year(postDateTime),"-",month(postDateTime),"-01") AS pDT,
COUNT(*) AS month_qty
FROM perch3_blog_posts p
WHERE year(postDateTime) = '2017'
AND p.postStatus='Published'
AND p.postDateTime<='2017-06-08 08:20:00'
GROUP BY year, month, pDT
ORDER BY month DESC
So, using an alias of pDT that differs to the actual existing column name of postDateTime seems to work. Now, I don't know if this is a peculiarity of mySQL or whether I have done something else amiss.
What do you think?
Thanks
James
Please post your Diagnostics Report.
Hi Rachel - Sorry should have done that first time around. Here it is.
Hi Rachel - Just wondering if you have had a chance to investigate my query any further? For now I have removed the counts from being displayed.
Thanks,
James
By the way, I have updated to the latest version of Perch and the problem is still occurring. Diagnostic report below...
We'll certainly look at it when we next update Blog.