Jump to content

Array SUM.... I have a headache


phpstuck

Recommended Posts

OK can someone please point me in the right direction... I have been through the manual, and all over google but I can't seem to figure this out.

 

I have two tables, one is named inven the other is named groc

 

In the inventory table there are food items made by different manufactures like Kroger canned corn, Aldi Canned Corn and Foodland Canned corn. each have a different "quan" They are linked by a sub cat in the "inven" table named groccat (all are set to "canned corn")  Over in the "groc" table there is a grocname that is also "canned corn" and a column named "min"

 

I am trying to get a sum from an array for all the different brands in the "inven" table that have a sub cat of "canned corn"  So instead of 2 cans of kroger and 3 cans of Aldi... I can get 5 cans of corn.

 

I have tried the following to no avail. along with a million other ways to try and put it together... Any help would be enough to get me moving again :-)

 

<?PHP

include_once 'db.php';

$deflist=mysql_query(        
"SELECT l.groccat, l.quant, b.grocname, b.min, b.tobuy FROM inven l,groc
b WHERE l.groccat = b.grocname");
while ($all = mysql_fetch_array($deflist)) {
   $results[$all['groccat']][] = array ('quant' => $all['quant'], 'grocname' => $all['grocname'], 'min' => $all['min'], 'tobuy' => 

$all['buy']);
}
$newquant = SUM($all[;quant']);

echo $newquant;






?>

Link to comment
https://forums.phpfreaks.com/topic/193520-array-sum-i-have-a-headache/
Share on other sites

Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.