This topic is locked

Delete records in multiple tables

9/21/2012 9:19:02 AM
PHPRunner General questions
J
Jeroef author

I can add and edit records in another table but having trubble to delete.
Main table is Main and i have 2 joined tables, join1 and join2.

when i add a new record in Main, join1 and 2 is populated with that value.
Sometimes i need to delete a record from Main and i need it to delete it from join 1 and 2 too.
Pls advice.
Regards Roger

C
copper21 9/21/2012

Jeroef,
I just did the same thing a few days ago....here is my code. I put it in List Page - After record deleted event:
// Delete Data from Join1
global $dal;
$tblJoin1 = $dal->Table("Join1");
$tblJoin1->Param["join1_field"]="".$deleted_values['main_table_id']."";
$tblJoin1->Delete();
//Delete Date from Join2
global $dal;
$tblJoin2 = $dal->Table("Join2");
$tblJoin2->Param["join2_field"]="".$deleted_values['main_table_id']."";
$tblJoin2->Delete();
All you have to do is change Param to the field name from Join1 and Join2 that is joined to the main table, and then change the name of the field in the "deleted values" variable to match the name of the field on the main table that is joined to Join1 and Join2. Hope this helps,
Brian

C
cgphp 9/21/2012

Declare the $dal object only one time. You don't need double quotes before and after the $deleted_values array.

global $dal;
$tblJoin1 = $dal->Table("Join1");
$tblJoin1->Param["join1_field"]=$deleted_values['main_table_id'];
$tblJoin1->Delete();
//Delete Date from Join2
$tblJoin2 = $dal->Table("Join2");
$tblJoin2->Param["join2_field"]=$deleted_values['main_table_id'];
$tblJoin2->Delete();
J
Jeroef author 9/22/2012

Works perfectly, thanks for that!
Is it possible to put a WHERE in there so it seeks out a certain field?
/Regards



Declare the $dal object only one time. You don't need double quotes before and after the $deleted_values array.

global $dal;
$tblJoin1 = $dal->Table("Join1");
$tblJoin1->Param["join1_field"]=$deleted_values['main_table_id'];
$tblJoin1->Delete();
//Delete Date from Join2
$tblJoin2 = $dal->Table("Join2");
$tblJoin2->Param["join2_field"]=$deleted_values['main_table_id'];
$tblJoin2->Delete();


C
cgphp 9/23/2012

Add a new param statement:

$tblJoin1->Param["field_name"]="test";


More info here: http://xlinesoft.com/phprunner/docs/delete.htm

J
Jeroef author 9/26/2012



Add a new param statement:

$tblJoin1->Param["field_name"]="test";


More info here: http://xlinesoft.com/phprunner/docs/delete.htm


Thanks again.