my array is almost working as designed. the problem is the counter variables: $cat['piece_count'] and $cat['total_price']. They aren't incrementing appropriately, they're just sticking with their inital values... Any thoughts?
Code:
$category=array( array(
"id"=>-1,
"name"=>"",
"piece_count"=>1,
"total_price"=>1
) );
$totalinventorysales=0;
$totalquantity=0;
while ($line=mysql_fetch_array($piece_result)) {
$totalinventorysales=$totalinventorysales+$line['price'];
$totalquantity=$totalquantity+$line['quantity'];
$newcategory=0;
$pointer=0;
foreach ($category as $cat) {
if ($cat['id']==$line['category_id']) {
THIS LINE->> $cat['piece_count']++;
AND THIS LINE->> $cat['total_price']=$cat['total_price']+$line['price'];
$newcategory=1;
}
}
if ($newcategory==0) {
$name=show_category($line['category_id'],$conn);
array_push($category,array(
"id"=>$line['category_id'],
"name"=>$name,
"piece_count"=>1,
"total_price"=>$line['price']
));
}
}
//remove first, blank category
$name=array_shift($category);
unset($name);