View Single Post
Old 03-29-2006, 01:28 PM   #9 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,505
sde is on a distinguished road
ok, let me know if this helps. read the comments.
PHP Code:
<?
// build categories array at the top of every page
$result mysql_query("select c.category_id, c.category_name, c.category_description, 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"
); 

// declare an array (just a safeguard for when we use foreach below)
$categories = array();

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

// buld your table with the array
foreach ($categories as $category) {

    
// use the ternary operator to easily switch your colors in 1 line
  
$color = ($color == $color1) ? $color2 $color1;
  
  
// print your category menu
  
echo "<tr style=\"background-color:$color\">\n
  <td width=\"100\"><p>" 
$category['category_name'] . " (" .$category['count'] . ")</p></td>\n
  <td width=\"300\"><p>" 
$category['category_description']. "</p></td>\n
  <td width=\"145\"><p><a href=\"display_category.php?category_id=" 
$category['category_id'];. "\">View</a> | <a href="edit_category.php?category_id=" . $category['category_id'] . "">Edit</a> | <a href=\"javascript:BRB_PHP_DelWithCon('delete_category.php','category_id'," $category['category_id'] . ",'Are you sure you want to delete this category?');\">Delete</a></p></td>\n
</tr>\n"
;

}

// ok, so now we're on display_category.php.
// this could be on the same page as the menu table
// or a different one, the important thing is that our
// $categories array is defined.

// now we set the current category from the category
// defined in the URL query string
$current_category $categories[$_GET['category_id']];

echo 
"The current category is: " $current_category['category_name'];
?>
sde is offline   Reply With Quote