Hi Guys:
I have a one to many relationship between a ParentCost table and a ChildCost table.
I would like to update the field Cost3 in the parent table with the SUM of field Cost3 in the child table.
ParentCost
ID
Cost1
Cost2
Cost3
ChildCost
ChildID
ParentID
Cost3
I have the following update code that works fine for regular updates, but I don't know how to rewrite it so that it will sum the Cost3 field in the child table
before updating it on the parent table:
{
$str = "select ParentID from ChildCost where".$where;
$rs = db_query($str,$conn);
while ($data = db_fetch_array($rs))
{
$str2 = "update `ParentCost` set `Cost3`='".$values["Cost3"]."' where `ID`=".$data["ParentID"];
db_exec($str2,$conn);
}
}
Any help is much appreciated.
Thanks!