This topic is locked

put total summary from details table to master

1/10/2008 5:27:00 AM
PHPRunner General questions
M
marpunta author

Hi there

I am very new to all these and i am trying to do something easy to some of you but obviously difficult to me.

This is it

I have a master table named _oikonomika with these fields id, paragvgh, xrevsh, kostos, kerdos

and a details table named _dapanes with these fields id, paragvghDAP, prom, kostosDAP

the join is paragvgh and paragvghDAP (this was dne through the datasource tables from PHPrunner tab)
Now my questions are

1.How can i put the total amount of kostosDAP from the details table for a certain record of paragvgh to the field kostos

and then

2.calculate xrevxh-kostos and put it into kerdos

Thank you

J
Jane 1/11/2008

Hi,
you can do it using After record added/After record updated event for this purpose.

Here is a sample code:

global $conn,$strTableName;

$str = "select sum(kostosDAP) from _dapanes where paragvghDAP=".$_SESSION[$strTableName."_masterkey1"];

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

$data = db_fetch_numarray($rs);
$strUpdate = "update _oikonomika set kostos=".$data[0]." where paragvgh=".$_SESSION[$strTableName."_masterkey1"];

db_exec($strUpdate,$conn);


Make the same for xrevxh-kostos and kerdos fields.

M
marpunta author 1/13/2008

Hi,

you can do it using After record added/After record updated event for this purpose.

Here is a sample code:
Make the same for xrevxh-kostos and kerdos fields.


Hi Jane and thank you for your answer

Because i know almost nothing about mySQL i am trying to under understand and learn from your code

So what really is _masterkey1 and what exactly it represents?

Because when i put your code to an after record event try to add a new record it gives me this error
Error type 256

Error description Unknown column `test` in `where clause`

URL localhost/ttt/_dapanes_add.php

Error file w:\www\ttt\include\dbconnection.php

Error line 26

SQL query insert into `_dapanes`(`prom`,`kostosDAP`,`paragvghDAP`) values (`cfgb`,`555`,`test`)
test is the common value between paragvgh and paragvghDAP
Also for the Make the same for xrevxh-kostos and kerdos fields i cant figure out where to put the custom code
Thank you

J
Jane 1/14/2008

Hi,
you need to add single quotes around text field in teh SQL query, i.e.

...

$str = "select sum(kostosDAP) from _dapanes where paragvghDAP='".$_SESSION[$strTableName."_masterkey1"]."'";

...

$strUpdate = "update _oikonomika set kostos=".$data[0]." where paragvgh='".$_SESSION[$strTableName."_masterkey1"]."'";

...


Regarding the second question.

You can add your code to the After record added/After record updated event for the same table.