This topic is locked

Show sum from Child table to main table

11/5/2009 8:41:14 AM
PHPRunner General questions
G
gaty author

Hi,
I have 2 tables "Purchase" and "Invoices" , link fields are ControlNo and AControlno.

Invoices has 2 fields Paid and Rate. Purchase has Totalpaid.

I want to sum up (Paid * Rate) into Totalpaid, where ControlNo and AControlno are same.



global $conn;
$str = "select sum(`paid` * `rate`) from invoices where Acontrolno = '{$values["controlno"]}'";

$rs = db_query($str,$conn);

$data = db_fetch_numarray($rs);

$ttl=$data[0];

$strUpdate = "update purchase set `totalpaid`= '{$ttl}' where controlno = '{$values["controlno"]}'";

db_exec($strUpdate,$conn);


I Get following error:



PHP error happened

Technical information

Error type 256

Error description You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'where ControlNo=123/23' at line 1

URL localhost/PHPRunner/invoices_edit.php?

Error file C:\Documents and Settings\Administrator\Desktop\mowes_portable\www\accounts\output\include\dbconnection.php

Error line 34

SQL query Update purchase set TotalPaid= where ControlNo=123/23

Solution
This is a general error. It occurs when there is an error in event code or in SQL.


The Purchase table is also not getting update.
Please help.
B.

J
Jane 11/5/2009

Hi,
please see my changes below:

global $conn;
$str = "select sum(`paid` * `rate`) from invoices where Acontrolno = '".$values["controlno"]."'";

$rs = db_query($str,$conn);

$data = db_fetch_numarray($rs);

$ttl=$data[0];

if ($ttl)

{

$strUpdate = "update purchase set `totalpaid`= ".$ttl." where controlno = '".$values["controlno"]."'";

db_exec($strUpdate,$conn);

}
G
gaty author 11/5/2009

Hi,
Thanks for the quick help.

After putting the code, the purchase table is still not updating with the totals.
Pls help.
B.

Sergey Kornilov admin 11/5/2009

I recommend to post your application to Demo Account (use 'Demo Account' button on the last screen in program). Then open a ticket at http://support.xlinesoft.com sending your Demo Account URL for investigation.