Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

product count, how to get?


ttt2

Recommended Posts

Posted

I need to get the product count in a category. I came across this function in general.php, but not sure how to use it. It looks like I need to pass category_id into the function. I havn't found how to get category_id. Can any one help? By the way i'm modifying product_listing.php so category_id will change often.

 

function tep_count_products_in_category($category_id, $include_inactive = false){

$products_count = 0;

if ($include_inactive == true) {

$products_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c where p.products_id = p2c.products_id and p2c.categories_id = '" . (int)$category_id . "'");

} else {

$products_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c where p.products_id = p2c.products_id and p.products_status = '1' and p2c.categories_id = '" . (int)$category_id . "'");

}

$products = tep_db_fetch_array($products_query);

$products_count += $products['total'];

 

$child_categories_query = tep_db_query("select categories_id from " . TABLE_CATEGORIES . " where parent_id = '" . (int)$category_id . "'");

if (tep_db_num_rows($child_categories_query)) {

while ($child_categories = tep_db_fetch_array($child_categories_query)) {

$products_count += tep_count_products_in_category($child_categories['categories_id'], $include_inactive);

}

}

 

return $products_count;

}

Posted

is this for a report or to be displayed in a store?

Posted
is this for a report or to be displayed in a store?

 

no, I just need the number to calculate display layout. I installed a add-on that display products in columns and making some enhancement to it. I need the total product number so I can add dividing lines to the cells. Right now, either I have to many dividing lines or too little. I probably making this to complicated. :lol: There are other mods like it, but I like this better. :P

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...