query($z); $total=0; while($r=$GLOBALS['db']->fetchByAssoc($w)) { if($r['type']=="0" || $r['type']=="2")$total+=$r['quantity']; elseif($r['type']=="1") $total-=$r['quantity']; }*/ $q1=0; $w=$GLOBALS['db']->query("select quantity as qty,id,price,product_id from ecmcashoperations where deleted='0' and type='0' and in_id IS NULL".$stock." and product_id='".$_GET['id']."'"); while($rrr=$GLOBALS['db']->fetchByAssoc($w)){ print $rrr['product_id'].'
'; $ww=$GLOBALS['db']->query("select quantity from ecmcashoperations where in_id='".$rrr['id']."' and type='1' and in_id IS NOT NULL".$stock." and product_id='".$_GET['id']."' and deleted='0'"); $rqty=0; while($rrp=$GLOBALS['db']->fetchByAssoc($ww)){ $rqty+=$rrp['quantity']; } $qty=$rrr['qty']-$rqty; if($qty>0){ $arr[]=array("qty"=>$qty,"id"=>$rrr['id'],"price"=>$rrr['price']); } } echo '
';
print_r($arr);
echo '
'; if(count($arr)>0){ foreach($arr as $v){ $q1+=$v['qty']; $pp1+=$v['qty']*$v['price']; } } print $q1; ?>