<?php 

$db=$GLOBALS['db'];
$r=$db->query("select * from ecmnoteouts");
while($a=$db->fetchByAssoc($r)){
   $db->query("update ecmnoteouts set purchase_price=(select round(sum(quantity*price_purchase),2) as sum from ecmnoteoutitems 
 where  ecmnoteout_id='".$a['id']."') where id='".$a['id']."'
           ");
}
?> 