need coding help
Posted: Wed Oct 05, 2011 9:27 pm
I use 2 databases,(numbersdb) has one record with the field "balance". it is read once to retrieve the balance value for storage. This database is updated at the end.
the other database (ckdb) has the several records for the report.
All works except that my code does not get the balance from the nunbersdb. I could really use some adice.
the other database (ckdb) has the several records for the report.
All works except that my code does not get the balance from the nunbersdb. I could really use some adice.
Code: Select all
<?php
// **this database has one record with a field named "balance" which
// will, at the end, be updated
mysql_connect("localhost","root","");
mysql_select_db('numbersdb') or die( "Unable to select database");
// query ="USE db1; Select * from table.....
$query=" SELECT balance FROM numbdata where id='id'";
$result=mysql_query($query);
$num=mysql_num_rows($result);
// echo " balance is $num <br />";
// **this database has the bank records**
mysql_select_db('ckdb') or die( "Unable to select database");
// query ="USE db2; Select * from table.....
$query=" SELECT * FROM ckcust ORDER BY dateord ASC";
$result=mysql_query($query);
$num=mysql_numrows($result);
error_reporting(0);
echo date("m/d/Y") . "<br />";
echo "<table cellspacing=1 cellpadding=0 border=0>
<tr>
<th>Inv#</th>
<th>description</th>
<th>date</th>
<th align=right>charges</th>
<th align=right>paid</th>
<th align=right>owed</th>
<th align=right>balance</th>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td align=right>" . sprintf("%.2f",$balance) .
"</td>
<tr>
<TH colspan=9>=======================================================================</TH>
</tr>";
while($row = mysql_fetch_array($result))
{
// * calcs********************************
$owed = $row['charges'] - $row['paidamt'];
$nubalance = $row['balance'] - $row['paidamt'];
// $nubalance = $nubalance - $row['paidamt'];
$totpaid = $totpaid + $row['paidamt'];
$totcharges = $totcharges + $row['charges'];
$totowed = $totowed + $owed;
// * end calcs*****************************
echo "<tr>";
echo "<td>" . $row['invnum'] . "</td>";
echo "<td>" . $row['bname'] . "</td>";
echo "<td>" . $row['dateord'] . "</td>";
echo "<td align=right>" . $row['charges'] . "</td>";
echo "<td align=right>" . $row['paidamt'] . "</td>";
echo "<td align=right>" . sprintf("%.2f",$owed) .
"</td>";
echo "<td align=right>" . sprintf("%.2f",$nubalance) .
"</td>";
}
echo "<tr>";
echo "<th colspan=9>=======================================================================</TH>";
echo "<tr>";
echo "<td>Gtotals</td>";
echo "<td></td>";
echo "<td></td>";
echo "<td align=right>" . sprintf("%.2f",$totcharges) .
"</td>";
echo "<td align=right>" . sprintf("%.2f",$totpaid) .
"</td>";
echo "<td align=right>" . sprintf("%.2f",$totowed) .
"</td>";
echo "</tr>";
echo "</table>";
mysql_query("UPDATE numbdata SET balance='$nubalance'");
echo "New balance of $ ".$_POST["nubalance"]." has been updated";
mysql_close();
?>