Hello,
I've been trawling through the forum post cherry picking mods to use and I found (but have now lost) a site or a bit of code that showed how to display the total number of products in the database along with the number of brands etc.
If you know where it is or what it is, please let me know.
Thanks,
Ben
Wardrobe Workout.co.uk
Wardrobe Workout.com
Hi Dave,
Is it possible that we can use this code but instead of printing it can we insert into totals_cache database and then query each field to display on site?
Kind Regards
Darren
Hi Darren,
Sure - assuming a totals_cache table with fields num_products,num_categories and num_brands, something like this would do the trick:
<?php
// products
$sql = "SELECT count(*) as numProducts FROM `".$config_databaseTablePrefix."products`";
database_querySelect($sql,$rows);
$numProducts = $rows[0]["numProducts"];
// categories
$sql = "SELECT count(DISTINCT(category)) as numCategories FROM `".$config_databaseTablePrefix."products`";
database_querySelect($sql,$rows);
$numCategories = $rows[0]["numCategories"];
// brands
$sql = "SELECT count(DISTINCT(brand)) as numBrands FROM `".$config_databaseTablePrefix."products`";
database_querySelect($sql,$rows);
$numBrands = $rows[0]["numBrands"];
$sql = "TRUNCATE `".$config_databaseTablePrefix."totals_cache`";
database_queryModify($sql,$result);
$sql = "INSERT INTO `".$config_databaseTablePrefix."totals_cache` SET
num_products = '".$numProducts."',
num_categories = '".$numCategories."',
num_brands = '".$numBrands."'
";
database_queryModify($sql,$result);
?>
...and then to display;
<?php
$sql = "SELECT * FROM `".$config_databaseTablePrefix."totals_cache`";
database_querySelect($sql,$rows);
print " Total Products: ".$rows[0]["num_products"];
print " Total Categories: ".$rows[0]["num_categories"];
print " Total Brands: ".$rows[0]["num_brands"];
?>
Cheers,
David.
Hi Dave,
Many thanks works a treat
Best Regards
Darren
Hi David,
I followed the procedure to display the total number of products and brands present in my database by adding this code:
<?php
// products
$sql = "SELECT count(*) as numProducts FROM `".$config_databaseTablePrefix."products`";
database_querySelect($sql,$rows);
$numProducts = $rows[0]["numProducts"];
print "<p>Plus de ".$numProducts." modèles disponibles parmi";
// brands
$sql = "SELECT count(DISTINCT(brand)) as numBrands FROM `".$config_databaseTablePrefix."products`";
database_querySelect($sql,$rows);
$numBrands = $rows[0]["numBrands"];
print " ".$numBrands." Boutiques</p>";
?>
This works fine except that i would add the "merchants"
Can you help me ?
Thnks
Fred
Hello Fred,
It is similar to the brands once... Use this:
// merchants
$sql = "SELECT count(DISTINCT(merchant)) as numMerchants FROM `".$config_databaseTablePrefix."products`";
database_querySelect($sql,$rows);
$numMerchants = $rows[0]["numMerchants"];
print " ".$numMerchants." Merchants</p>";
Cheers,
David.
Hi Ben,
There is product count code in this thread - shown below with additional queries to select category and brand count; however beware of the resource implications that this may put on your server. If you find it is too slow to load as a result (if you have thousands of products) it may be necessary to create cached versions which are only updated whenever you import - but that is quite a lot more code...!
<?php
// products
$sql = "SELECT count(*) as numProducts FROM `".$config_databaseTablePrefix."products`";
database_querySelect($sql,$rows);
$numProducts = $rows[0]["numProducts"];
print "<p>Total products in database: ".$numProducts."</p>";
// categories
$sql = "SELECT count(DISTINCT(category)) as numCategories FROM `".$config_databaseTablePrefix."products`";
database_querySelect($sql,$rows);
$numCategories = $rows[0]["numCategories"];
print "<p>Total categories in database: ".$numCategories."</p>";
// brands
$sql = "SELECT count(DISTINCT(brand)) as numBrands FROM `".$config_databaseTablePrefix."products`";
database_querySelect($sql,$rows);
$numBrands = $rows[0]["numBrands"];
print "<p>Total brands in database: ".$numBrands."</p>";
?>
Cheers,
David.