Forum Moderators: coopster
anyone have a suggestion what i did wrong?
function tep_count_products_in_manufacturer($manufacturers_id, $include_inactive = false) {
$manu_count = 0;
if ($include_inactive == true) {
$manu_products_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS . ", " . TABLE_MANUFACTURERS . " where products.manufacturers_id = manufacturers.manufacturers_id and manufacturers.manufacturers_id = '" . (int)$manufacturers_id . "'");
} else {
$manu_products_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS . ", " . TABLE_MANUFACTURERS . " where products.manufacturers_id = manufacturers.manufacturers_id and products.products_status = '1' and manufacturers.manufacturers_id = '" . (int)$manufacturers_id . "'");
}
$manu_products = tep_db_fetch_array($manu_products_query);
$manu_count += $manu_products['total'];
return $manu_count;
}
$my_query="SELECT * FROM...... ";
$my_result = mysql_query($my_query) or die(mysql_error().'<p>Error found in: '.$my_query.'</p>');
while ($my_myrow = mysql_fetch_array($my_result))
{
// do something with results
}
Also try to echo somethig like:
echo "select count(*) as total from " . TABLE_PRODUCTS . ", " . TABLE_MANUFACTURERS . " where products.manufacturers_id = manufacturers.manufacturers_id and manufacturers.manufacturers_id = '" . (int)$manufacturers_id . "'" "; and see what it goes into your query
i just hacked that func within a clients osc setup lately.
this query is supposed to hide any categories with 0 products
doesn't it hide inactive categrories only? otherwise there would be a need of a join first not a cross-query over both tables i assume. or a better where clause. but shouldn't be categrories with 0 products disabled anyway?
so maybe this is not a php based prob at all, right?
omoutop:
check the first line of your function
$include_inactive = false // never becomes true?
for echoing the query - which is a good idea to debug - , please use this line:
echo('<pre>' . htmlspecialchars($manu_products_query). '</pre>');
because this will contain the exact query which is passed to your database server.
keep in mind with another peoples source code to understand it fully first otherwise you will run into many problems. the osc source is not the best-structured one so you will need some time for this but you will be rewarded afterwards ;).