Page 1 of 1

Help finding the number of content items in a category

Posted: Sun Feb 24, 2008 11:24 pm
by moseleysc
Hello there,

I'm new to Joomla coding.....new to php and mysql. I come from a more creative perspective but in creating a site for a client I realized that I needed to implement a solution that isn't out there yet.

I've done a lot of seaching but some of the articles in the Joomla forum indexed by Google don't seem to be there anymore (maybe after the forum change?).

I could really use some help on a basic task here....The quick question is, how do I set up the database query to determine the number of articles or content items in a particular category?

I'm using Joomla 1.0.x and the code will be running in a mambot if any of that matters.

I could really use the help. Thanks.

Regards,
Steve

Re: Help finding the number of content items in a category

Posted: Tue Feb 26, 2008 5:51 am
by permalink
For the number of content items in a category, you will need to join the two tables by pairing up their columns in common: the foreign key 'catid' in the content table and the primary key 'id' of the category table.

use this:

Code: Select all

SELECT count(c.id) FROM #__content c  
INNER JOIN #__categories AS cat ON cat.id = c.catid
WHERE cat.title = 'Languages'
or if you want to get details on the content items:

Code: Select all

SELECT c.id, c.title, c.sectionid, cat.id FROM #__content c  
INNER JOIN #__categories AS cat ON cat.id = c.catid
WHERE cat.title = 'Languages'
Hope that helps.