query("select product_code,product_id,price,id from ecmstockoperations where price=131 and date_modified>'2010-01-01'"); while($r=$GLOBALS[db]->fetchByAssoc($w)){ $rr=$GLOBALS[db]->fetchByAssoc($GLOBALS[db]->query("select purchase_price from ecmproducts where id='".$r['product_id']."'")); $rrr=$GLOBALS[db]->fetchByAssoc($GLOBALS[db]->query("select max(price) as max,min(price) as min from ecmstockoperations where product_id='".$r['product_id']."' order by date_entered desc")); if($rr['purchase_price']<=$r['price'] and $rr['purchase_price']>0){ echo $r['product_code']." ".$r['price']." ".$rrr['max']." ".$rrr['min']." ".$rr['purchase_price']."
"; //if($rrr['price'])$GLOBALS[db]->query("update ecmstockoperations set price='".$rrr['price']."' where id='".$r['id']."'"); } } ?>