Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2010-03-23 12:55:22

aslsw66
Member
From: Canberra, Australia
Registered: 2004-08-04
Posts: 342
Website

Using SQL to extract entries from 1 January of the current year

I have a section called ‘incidents’ to post articles about incidents our fire brigade attends.

What I now want to do is use smd_query to count the total number of incidents this year (ie. for any given year) and show this on the homepage. But I’m struggling with the right SQL query to use.

select count(*) from textpattern where section='incidents' correctly calculates the total number of incidents.

But when I try to calculate using the posted date of the article, I just can’t seem to get the SQL query right. For example, select count(*) from textpattern where section='incidents' where year(Posted) = '2010' doesn’t work.

I’ve been trawling around on Google to find a solution but I’m stumped. Can anyone offer an idea?

Thanks

Offline

#2 2010-03-23 13:06:14

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,942
Website GitHub

Re: Using SQL to extract entries from 1 January of the current year

aslsw66

Sooo close. Try:

select count(*) from textpattern where section='incidents' AND year(Posted) = '2010'

The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#3 2010-03-23 13:18:58

aslsw66
Member
From: Canberra, Australia
Registered: 2004-08-04
Posts: 342
Website

Re: Using SQL to extract entries from 1 January of the current year

OK, fair enough, but in my defence it’s after midnight here! I think I will wait until tomorrow to insert this into the page and make it work – I’m at the stage where I will probably just break something.

Thanks again for your help. smw_query is an awesome plugin.

Offline

#4 2010-03-23 14:29:58

Dragondz
Moderator
From: Algérie
Registered: 2005-06-12
Posts: 1,549
Website GitHub Twitter

Re: Using SQL to extract entries from 1 January of the current year

aslsw66 a écrit:

Thanks again for your help. smw_query is an awesome plugin.

Sure it too late for you, (smd_query become smw_query) ;)

Offline

Board footer

Powered by FluxBB