Sum of a field from another Table

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
Stevo2112
Posts: 10
Joined: 2015-01-14 15:05

Sum of a field from another Table

Post by Stevo2112 » 2015-01-21 14:50

Not a question... But I searched the forum for this and did not find it, so I thought that this might help someone out, who was looking to do the same thing. :arrow:



Sum a field from Another Table

function OrderTot_after_insert($data, $memberInfo, &$args){

$id = makeSafe($data['OrderID']);
$tot = sqlValue("SELECT SUM(OrdTot) FROM order_details WHERE OrderID='$id' ");
sql("UPDATE OrderTot SET OrdItemTot = '$tot' WHERE OrderID='$id'", $eo);


return TRUE;
}

jstrick
Posts: 13
Joined: 2013-03-04 20:55

Re: Sum of a field from another Table

Post by jstrick » 2016-05-09 22:40

Just a little more info on this and thanks a bunch to stevo.
I worked on this issue for a long time and finally one day something clicked.
Just a side note if your not a pro at this stuff give up the info the majority of the people here from what i see are novice just trying to make a click work. Help out your fellow man and make that click work. Your heart will feel better when you see a thank you well....

ok on to business.

$id = makeSafe($data['this needs to be what ever you call your ID']);
$tot = sqlValue("SELECT SUM(Your field name that you want to show) FROM your table name WHERE your id field ='$id' ");
sql("UPDATE Invoice SET your field you want to update = '$tot' WHERE your id number='$id'", $eo);

It is great script it pulls all the data from another table based on ID

So if you have a table in my case work orders and another table called employee time it will grab all the employee time based on the work order id so if a guy has twelve hours based over a six day period it will put them into one field. in this case invoice table.

so i have three tables
work orders
employee time
invoice
in those three tables is a common field called workorderId
so all tables are linked by this.

ok not great at explaining but if this looks like something you are trying to do contact me and i will try and help.

Again thanks Stevo2112 you solved my issue.

Mahmud
Posts: 12
Joined: 2017-03-12 08:53

Re: Sum of a field from another Table

Post by Mahmud » 2017-04-23 01:40

not clear ..! please give us details........

xbox2007
Veteran Member
Posts: 129
Joined: 2016-12-16 16:49

Re: Sum of a field from another Table

Post by xbox2007 » 2018-02-18 15:58

hello
what about calculate sum by using JavaScript , then use ajax to update value to other table

Post Reply