Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

HELP: How to not count all products


t000

Recommended Posts

Hi.

Im using this script in in the includes/functions/general.php file:
 

  function tep_count_products() {
   $products_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS . " WHERE products_status = '1'");
   $products = tep_db_fetch_array($products_query);

   return $products['total'];
 }


And this to call up the function in bm_information.php file with this:

           '       Total: '. tep_count_products (). ' items'.

This works and displays total products in the database. But I want it to display all product (-minus the products in one specific category).

Example:

Computers (1)
Laptops (1)
Batteries (3)
Keyboards (2)

Total: 7 items.

// I want it to display Total: 5 items, not counting products in the Keyboard category.

Running: osCommerce Online Merchant v2.3.4 and MySQL Client API version 5.5.55 / Client API header version 5.5.46

Link to comment
Share on other sites

You should be able to change the query and add something like....

and category_id not equal to X and category_id not equal to Y.

...after the where statement.

Dan

 

Link to comment
Share on other sites

  • 3 weeks later...

 

On 6/4/2017 at 11:51 PM, Dan Cole said:

You should be able to change the query and add something like....

and category_id not equal to X and category_id not equal to Y.

...after the where statement.

Dan

 

 

On 6/4/2017 at 11:59 PM, Dan Cole said:

Opps....and of course you'll need to join the products_to_categories table so you can get the category_id.

Dan

 

 

@Dan Cole thanks for your answer, im only a hobby and novice programer, I need some more corrections. Could you please help?

 

Regards.

Link to comment
Share on other sites

Quote

I need some more corrections. Could you please help?

@t000Corrections?...if you mean more direction tell us what you've done or where you're stuck and we'll see what we can do to help.

Dan

 

Link to comment
Share on other sites

@t000

Tom, will you always want to only exclude the Keyboard category, or will what you exclude change each time?

As you know, the tep_count_products() function counts *all* products.

function tep_count_products() {
   $products_query = tep_db_query("select count(*) as total
                                    from " . TABLE_PRODUCTS . "
                                    WHERE products_status = '1'");  
   $products = tep_db_fetch_array($products_query);    
   return $products['total'];
}

 

If you wanted to exclude the Keyboard category, you would have to change the function to *something* like this:

function tep_count_products() {
   $products_query = tep_db_query("select count(*) as total 
                                   from " . TABLE_PRODUCTS . " 
                                   WHERE products_status = '1'
                                     and Category ! Keyboards ");
   $products = tep_db_fetch_array($products_query);
   return $products['total'];
}

(No, that's not proper SQL code ... I'm just showing you *where* to adjust the query, not *how* to. You'll learn more about how to manage your own store by figuring it out yourself :cool:)

Two points:

1) You don't want to CHANGE the existing tep_count_products() function, you want to COPY and RENAME it (to something like tep_count_products_except_keyboards() ). Don't change the core code!

2) If you will be changing what you will be excluding each time, you could

  a) write a function for each category you might exclude (not too practical, especially if you may want to exclude more than one category, and/or you add new categories to your store often), or

  b) write a function that accepts a parameter with the category (or categories) you want to exclude. For example, you could write a function called tep_count_products_with_exceptions() , and would have to pass the name or number of the category (or categories) that you want to exclude.

See what you can come up with. If you need more help, tell us what you have tried that worked or didn't work.

HTH

Malcolm

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...