Somebody please help with this code. I have been tryin to calculate and display the total of the total output from an oracle database.

Please see my code below and kindly tell how i can display the total.

<?php


$conn = oci_connect("Username", "pwd", "IP/tns");


$date=date('d M Y');
$total= oci_parse($conn, "select SUM(ACCT_HISTORY.GROSS_AMOUNT) from ACCT_HISTORY where TRAN_DATE BETWEEN '01-APR-2010' AND '30-APR-2010'
AND TRAN_SOURCE ='1'");
Oci_execute($total);
$calculate = oci_fetch($total);


$stid = oci_parse($conn, "SELECT ACCT_HISTORY.DC_NUMBER,ACCT_HISTORY.POLICY_NUMBER,ACCT_HISTORY.TRAN_DATE, ACCT_HISTORY.GROSS_AMOUNT,policy_master.sum_insured,policy_Class.Description,
Policy_Master.Holder_Name FROM ACCT_HISTORY, Policy_master, POLICY_CLASS WHERE TRAN_DATE >= '$date' AND TRAN_SOURCE ='1' AND Policy_Class.Policy_class = ACCT_HISTORY.Policy_Class
AND Policy_Master.Policy_Number=Acct_History.Policy_Number ORDER BY TRAN_DATE
");


oci_execute($stid);


$nrows = oci_fetch_all($stid, $results);


echo "<html><title>!!Daily Transaction!!</title></head><body>";
echo "<center><h2>Legend Transactions for $date </h2><br>";
echo "<table border=1 cellspacing='0' width='70%'>\n<tr>\n";
echo "<td><font color='blue' size='2'><b>Policy Number</b></td>\n<td><font color='blue' size='2'><b>Debit Note Number</b></td>\n<td><font color='blue' size='2'><b>Insured</b></td>\n
<td><font color='blue' size='2'><b>Policy Type</b></td>\n<td><font color='blue' size='2'><b>Transaction Date</b></td>\n<td><font color='blue' size='2'><b>Premium</b></td>\n<td><font color='blue' size='2'><b>Sum Insured</b></td>\n</tr>\n";


for ($i = 0; $i < $nrows; $i++ ) {
echo "<tr>\n";
echo "<td><font size='1'>" . $results["POLICY_NUMBER"][$i] . "</td>";
echo "<td><font size='1'>" . $results["DC_NUMBER"][$i] . "</td>";
echo "<td><font size='1'>" . $results["HOLDER_NAME"][$i] . "</td>";
echo "<td><font size='1'>" .$results["DESCRIPTION"][$i]. "</td>";
echo "<td><font size='1'>" . $results["TRAN_DATE"][$i] . "</td>";
echo "<td align='right'><font size='1'>" . number_format($results["GROSS_AMOUNT"][$i],2,'.',',');"</td>";
echo "<td align='right'><font size='1'>" . number_format($results["SUM_INSURED"][$i],2,'.',',');"</td>";



echo "</tr>\n";
}


echo "<br><tr><td>$calculate</td><td></td><td></td><td></td></tr></table>";
echo "<br><em>End of Report</em><br></center></body></html>\n";


?>

Your problem is with $calculate = oci_fetch($total); $calculate is catching a BOOL value of whether the fetch was successful or not.

What you want to be doing instead is oci_fetch_array and then obtain the value out of the first column.

$res = oci_fetch_array($total, OCI_NUM);
$calculate = $res[0];
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.