This topic is locked

Delete info from master en detail table

11/8/2005 3:36:57 AM
PHPRunner General questions
OCTheEagle author

The situation is as follows I have 2 tables which have a master-detail relationship.
Mastertable

Field 1 = ID

Field 2 = name
Detailtable

Field 1 = ID

Field 2 = book
Let's say that we have an user called Hans with ID 5. Hans has three books. the detail table would look as follows

Field 1 Field 2

1 The Legacy begins

1 The Rock says

1 It's true it's true
When I delete Hans I want to remove the user ID's and books he has from detail table 2. I think I need to add a few lines in the file ....list.php after the sentence

$strSQL="delete from ".AddTableWrappers($strTableName)." where ".AddFieldWrappers($strKeyField)."=".$key;


My question is, what do I have to input?

Sergey Kornilov admin 11/8/2005

You can put your code just after this snippet:

LogInfo($strSQL);

db_exec($strSQL,$conn);


and it can look like this:

db_exec("delete from Detailtablewhere ID=".$key,$conn);


where Detailtable and ID are your actual table and foreign key names.

A
andyjames 9/5/2006

Building on the excellent solution given above for deleting linked detail table records when a master table record is deleted, is it possible to integrate the the global Delete file when associated record is deleted option so that if one of the detail tables has a file download/upload field, that it automatically deletes the associated file from the Folder where file resides (upload directory)?
Is this the BeforeDelete function?
Thanks for all your help on Deleting... Jane! It's been a lot of help.