$toplam = 0;
foreach(odbc_fetch_array($sorgu2) as item) {
if($item->STOCKREF) {
$toplam = $toplam + $item->ONHAND;
}
}

echo $toplam;