Finding out number of rows from a table
Posted: Thu May 18, 2006 12:08 pm
Hi,
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.
Idea 1
Idea 2
I know there's got to be a much better way. Any and all help would be appreciated.
Thank you
Sphen[/syntax]
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.
Idea 1
Code: Select all
// Get the number of categories
foreach ( $category_id as $category )
{
$sql = 'SELECT article_id
FROM article_table
WHERE article_category_id = ' . $category
}
Code: Select all
$sql = 'SELECT article_id
FROM article_table';
// Get resultset
if ( $row['article_id'] = '1' )
{
$cat1++;
}
// etc
Thank you
Sphen[/syntax]