t000 Posted June 4, 2017 Share Posted June 4, 2017 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 More sharing options...
Dan Cole Posted June 4, 2017 Share Posted June 4, 2017 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 Need help? See this thread and provide the information requested. Is your version of osC up to date? You'll find the latest osC community version (CE Phoenix) here. Link to comment Share on other sites More sharing options...
Dan Cole Posted June 4, 2017 Share Posted June 4, 2017 Opps....and of course you'll need to join the products_to_categories table so you can get the category_id. Dan Need help? See this thread and provide the information requested. Is your version of osC up to date? You'll find the latest osC community version (CE Phoenix) here. Link to comment Share on other sites More sharing options...
t000 Posted June 20, 2017 Author Share Posted June 20, 2017 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 More sharing options...
Dan Cole Posted June 20, 2017 Share Posted June 20, 2017 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 Need help? See this thread and provide the information requested. Is your version of osC up to date? You'll find the latest osC community version (CE Phoenix) here. Link to comment Share on other sites More sharing options...
ArtcoInc Posted June 22, 2017 Share Posted June 22, 2017 @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 ) 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 More sharing options...
ArtcoInc Posted June 22, 2017 Share Posted June 22, 2017 @t000 Oh, and as @Dan Cole mentioned, you are going to have to join tables in your query. More to learn If you don't feel that you can learn how to do this, you can always post in the commercial area of the forum and hire someone to do it for you. Malcolm Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.