Submitted by marco on Tue, 2008-04-15 09:35 in Price Tapestry
Hello,
My site with multiple installations (works great!) has on each installation (sub index) a product count installed.
Is it posible to combine the counts and have one total product count on the main index?
Something like this should be close; although i've not been able to test this without your setup. Change the names ("Database 1","Database 2" etc.) for each of the database names in your individual site's config.php's. The require() statements in the code below just need to point to one of your sites in order to pull in the library functions - it doesn't matter which site. Note that this is assuming each database has a different name but the same username / password / table prefix:
<?php require("site1/config.php"); require("site1/includes/database.php"); $count = 0; $databaseNames = array(); $databaseNames[] = "Database 1"; $databaseNames[] = "Database 2"; // etc. etc. foreach($databaseNames as $config_databaseName) { $sql = "SELECT SUM(products) AS numProducts FROM `".$config_databaseTablePrefix."feeds`"; database_querySelect($sql,$result); $count += $numProducts; } print "Total product count: ".$count; ?>
Hello Marco,
Something like this should be close; although i've not been able to test this without your setup. Change the names ("Database 1","Database 2" etc.) for each of the database names in your individual site's config.php's. The require() statements in the code below just need to point to one of your sites in order to pull in the library functions - it doesn't matter which site. Note that this is assuming each database has a different name but the same username / password / table prefix:
<?php
require("site1/config.php");
require("site1/includes/database.php");
$count = 0;
$databaseNames = array();
$databaseNames[] = "Database 1";
$databaseNames[] = "Database 2";
// etc. etc.
foreach($databaseNames as $config_databaseName)
{
$sql = "SELECT SUM(products) AS numProducts FROM `".$config_databaseTablePrefix."feeds`";
database_querySelect($sql,$result);
$count += $numProducts;
}
print "Total product count: ".$count;
?>
Cheers,
David.