This topic is locked

Event "after record added"

12/1/2010 3:21:54 PM
PHPRunner General questions
H
hokah author

This is all to you, PHPMySQL experts. In fact I need a syntax and hope some good soul out here is willing to help.

I'm using version 5.3 and as in title trying to exploit the "after record added" event.

Idea is there is one database, lets say 'db' and there are 2 tables 'table1' and 'table2'. 'table1'is the main table

with all the main data. 'table2' is for reporting purposes. In 'table2' user selects office and date range and after

save record in 'table2' this event calculates from the main 'table1' with query(office and between dates) sum of costs

from the main 'table1' and inserts it into 'table2' field 'cost'.

Any help would be appreciated.
Cheers.

kujox 12/2/2010



This is all to you, PHPMySQL experts. In fact I need a syntax and hope some good soul out here is willing to help.

I'm using version 5.3 and as in title trying to exploit the "after record added" event.

Idea is there is one database, lets say 'db' and there are 2 tables 'table1' and 'table2'. 'table1'is the main table

with all the main data. 'table2' is for reporting purposes. In 'table2' user selects office and date range and after

save record in 'table2' this event calculates from the main 'table1' with query(office and between dates) sum of costs

from the main 'table1' and inserts it into 'table2' field 'cost'.

Any help would be appreciated.
Cheers.


This should work, you might have to change the array names and put it in the before record added, not the after record added.



$sql = "SELECT SUM(costs) AS total FROM table1 WHERE office='" .$values['office']. "' AND date>='".$values['date_start']."' AND date<='".$values['date_end']."'";

$result = db_query($sql,$conn);

$data = db_fetch_array($result);

$values['total_cost'] = $data['total'];

// $values are the data to be saved