I'm looking to find the number of rows from a certain table in my database. They're articles, and I want to find out how many (approved) articles are in each category. I've thought of a few different ways, but I am wondering if anyone has any better ones.
// Get the number of categories
foreach ( $category_id as $category )
{
$sql = 'SELECT article_id
FROM article_table
WHERE article_category_id = ' . $category
}
Assuming that for each article_category there is at least one article in the article_table...
(Otherwise you'll have to perform an outer join, and use ifnull...)