Hi, I have a table in oracle database. It has columns purchase
sale
income
.
Now I want to show sum
of those values in INCOME
column and show in php page that total income is sum[INCOME]
. I tried to use a query with function. query seems not working. Here is the code.
<?php
function formatMoney($number, $fractional=false) {
if ($fractional) {
$number = sprintf('%.2f', $number);
}
while (true) {
$replaced = preg_replace('/(-?\d+)(\d\d\d)/', '$1,$2', $number);
if ($replaced != $number) {
$number = $replaced;
} else {
break;
}
}
return $number;
}
$c = oci_connect('SYSTEM', 'passward', 'db');
$result1 = oci_parse($c,"SELECT sum(INCOME) FROM TABLE WHERE SALE_DATE='$rdt'");
oci_execute($result1);
$row = oci_fetch_array($result1, OCI_ASSOC);
while($row = oci_fetch_array($result1, OCI_ASSOC))
{
$total=$row['sum(INCOME)'];
echo formatMoney($total, true);
}
?>