This topic is locked
[SOLVED]

 Update one to many

4/29/2010 11:49:21 AM
PHPRunner General questions
M
marpunta author

Hi again

It seems that more questions are coming.
I have a table called MAIN with two fields

MAINID and NAME
and a details table for that called DETAILS with three field

DETID DETMAIN and DETINFO
They are linked as master and detail with MAIN and DETMAIN fields
What i am trying to do is to edit NAME from MAIN and

update all details DETMAIN having the same name
...In other words "EDIT THE MASTER AND AUTO UPDATE ALL RELEVANT CHILDREN"
THANX again

Sergey Kornilov admin 4/29/2010

You need to use AfterEdit event of MAIN table. Here is the sample code:

$sql = "update DETAILS set DETINFO = '" . $values["NAME"] . "' where DETMAIN =" . $keys["MAINID"];

CustomQuery($sql);
M
marpunta author 4/30/2010

Hi Sergey

I didnt have any luck with your example

and i would like to explain it a little more
This is the MAIN table__|__This is the details table

____|___

MAINID.......NAME..............|......DETID.....DETMAIN.....DETINFO

1__John_
|__1_John____job1

2__George_
|__2_John____job2

____|__3_
John____Job3

____|__4George__Job6

____|__5
George__Job7

____| ... ... ...
The two tables are linked with NAME and DETMAIN
Now when i change the name from John to Peter i want all the DETMAIN listings in details

to change from John to Peter
I dont know if i am clear enough but i would like some help
Thanx again

A
ann 4/30/2010

Hi,

try the following code:

$sql = "update DETAILS set DETMAIN = '" . $values["NAME"] . "' where DETMAIN ='" . $oldvalues["NAME"]."'";

CustomQuery($sql);
M
marpunta author 4/30/2010



Hi,

try the following code:

$sql = "update DETAILS set DETMAIN = '" . $values["NAME"] . "' where DETMAIN ='" . $oldvalues["NAME"]."'";

CustomQuery($sql);




Thank you ANN

I will try it on Monday

BUT i am not sure it will work because of the link between NAME and DETMAIN