I think you might be going about this the wrong way, I can't
really get
my head around it.
I don't think you need a balance table. In your jobs table
you have an
numeric field for invoice amount, and a numeric field for
total paid.
Then you have SQL to display the SUM of the invoice amounts,
and the SUM
of the paid, then on the page itself, do a calculation for
what is
outstanding. You could do this in the SQL too.
SELECT SUM(jobs.invoice) AS InvoiceTotal, SUM(jobs.paid) AS
PaidTotal,
SUM(jobs.invoice) - SUM(jobs.paid) AS Outstanding
FROM jobs
WHERE jobs.cutomerid = ?
How does that sound?
Dooza
The_FedEx_Guy wrote:
> Basically mate,
> I'm trying to load the total amount that the customer
owes from his various
> jobs and add them to the "outstanding" field of the
balance table.
>
> I then have a textbox called "paid" and I want to
calculate the new amount the
> customer has paid and then update the "outstanding"
field to hold the new value.
>
> The calculation I have at the moment is in the code
below:
> $totalled = $row_total_cost['Total_Bal'] - $_GET[paid];
>
> Ideally when I add the job, I want to add the job, I
need the cost added to
> whatever is in outstanding field.
>
> But I have not created anything for that.
>
>
>
>
> mysql_select_db($database_db, $db);
> $query_total_cost = "SELECT SUM(job_cost) AS Total_Bal
> FROM customer LEFT JOIN jobs ON
customer.cust_business_name =
> jobs.cust_business_name
> WHERE jobs.cust_business_name =
'$_REQUEST[cust_business_name]' AND paid =
> 'No'";
> $total_cost = mysql_query($query_total_cost, $db) or
die(mysql_error());
> $row_total_cost = mysql_fetch_assoc($total_cost);
> $totalRows_total_cost = mysql_num_rows($total_cost);
>
> mysql_select_db($database_db, $db);
> $query_balances = "SELECT * FROM balance
> LEFT JOIN customer ON balance.cust_id = customer.cust_id
> LEFT JOIN jobs ON customer.cust_business_name =
jobs.cust_business_name
> WHERE customer.cust_business_name =
'$_REQUEST[cust_business_name]'";
> $balances = mysql_query($query_balances, $db) or
die(mysql_error());
> $row_balances = mysql_fetch_assoc($balances);
> $totalRows_balances = mysql_num_rows($balances);
>
>
> ?>
>
> <?php
> $currentPage = $_SERVER["PHP_SELF"];
> $totalled = $row_total_cost['Total_Bal'] - $_GET[paid];
>
> ?>
>
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN"
> "
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
> <html xmlns="
http://www.w3.org/1999/xhtml">
> <head>
> <meta http-equiv="Content-Type" content="text/html;
charset=utf-8" />
> <title>Admin</title>
> <link href="css/bc-stylesheet.css" rel="stylesheet"
type="text/css" />
> <style type="text/css">
> <!--
> .style3 {
> font-size: 14px;
> color: #FF0000;
> }
> -->
> </style>
> </head>
>
> <body>
> <table width="100%" border="0" cellspacing="3"
cellpadding="3">
> <tr>
> <td></td>
> </tr>
> </table>
> <table width="100%" border="0" cellspacing="2"
cellpadding="2">
> <tr>
> <td width="90%" valign="top"><table border="0"
align="center"
> cellpadding="0" cellspacing="0">
> <tr>
> <td><div align="center"><h1>Make
Payment</h1></div></td>
> </tr>
> </table>
> <form id="form1" name="form1" method="post"
action="">
> <form id="form2" name="form2" method="post"
action="<?php">
> <table width="500" border="0" align="center"
cellpadding="3"
> cellspacing="3">
> <tr>
> <td width="30" valign="top">Paid:</td>
> <td width="152" valign="top"><input type="text"
name="paid"
> id="paid" /></td>
> <td width="136" valign="top">New
Balance:</td>
> <td width="143" valign="top"><?php echo
$totalled;?></td>
> </tr>
> <tr>
> <td valign="top"></td>
> <td valign="top"> </td>
> <td valign="top"><input type="submit"
name="update" id="update"
> value="Update" /></td>
> <td valign="top"> </td>
> </tr>
> </table>
> </form>
> <table width="500" border="0" align="center"
cellpadding="2"
> cellspacing="2">
> <tr>
> <td valign="top"><span
class="style3">Balance Outstanding:
> <strong><?php echo
$row_total_cost['Total_Bal'];
?></strong></span></td>
> <td><div
align="right"></div></td>
> </tr>
> </table>
> <table width="100" border="0" align="center"
cellpadding="2"
> cellspacing="2">
> <tr>
> <td><input type="submit" name="Submit"
id="button"
> value="Submit" /></td>
> <td> </td>
> </tr>
> </table>
> </form>
> </td>
> </tr>
> </table>
> <p> </p>
> <p> </p>
> </body>
> </html>
> <?php
> //mysql_free_result($total_cost);
>
> mysql_free_result($balances);
> ?>
>
--
Posting Guidelines
http://www.adobe.com/support/forums/guidelines.html
How To Ask Smart Questions
http://www.catb.org/esr/faqs/smart-questions.html