View Single Post
Old 03-28-2006, 07:19 AM   #6 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,486
sde is on a distinguished road
in that case, i would create an array so it can be re-used. it can be keyed by category_id so you know which category you are accessing.
PHP Code:
<?
$result 
mysql_query("select c.category_id, c.category_name, count(a.article_id) as count from np_categories as c
  left join np_articles as a on c.category_id=a.article_category_id
  group by c.category_id
  order by c.category_name"
); 

while (
$row mysql_fetch_assoc($result)) {
  
$categories[$row['category_id']] = $row;
}

// now echo the name and article count of category id 15
echo $categories[15]['category_name'] . " (" $categories[15]['count'] . ")";
?>
sde is offline   Reply With Quote