Help finding the number of content items in a category

Have a programming question regarding your component, plug-in, extension or core hacks? Have an interesting tidbit, FAQ or programming tip you’d like to share? This is the place for you.

Moderators: tjay, seadap, Rogue4ngel, matthewhayashida

Post Reply
moseleysc
Joomla! Fledgling
Joomla! Fledgling
Posts: 1
Joined: Fri Nov 30, 2007 10:38 pm

Help finding the number of content items in a category

Post by moseleysc » Sun Feb 24, 2008 11:24 pm

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

permalink
Joomla! Apprentice
Joomla! Apprentice
Posts: 9
Joined: Tue Feb 19, 2008 5:36 pm

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

Post by permalink » Tue Feb 26, 2008 5:51 am

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.


Post Reply