blasalle
Posts: 69
|
| Posted: 01/03/2009, 5:22 PM |
|
Can anyone direct me to something that will tell me how use php custom code to insert into a second table when I submit a record. What I have is a project table with a many-to-many relation to a collaborator table. The resulting 'link-table 'project_collaborator' has the primary keys from each of these two tables (project and collaborator). When the coolaborator creates a project I need to insert into the link-table.
regards,
bernie
_________________
Bernie
University of Utah
Salt Lake City, UT USA |
 |
 |
sosamv
Posts: 50
|
| Posted: 01/04/2009, 8:32 PM |
|
Hi! Well I suppose you'll need the last inserted ID dont you?
I Grabed this code from the codecharge generated code (Theres is a post explaining how to do this the "WaltDisney way" LOL):
(Code inserted on AfterInsert function)
global $DBdevelopment; //DB(the name of you connection)
global $LastID;
$Page = CCGetParentPage($sender);
$ccs_result = CCDLookUp('last_insert_id()', '', '', $Page->Connections["development"]);
$ccs_result = strval($ccs_result);
$LastID = $ccs_result; //Las inserted ID
//Catch the array
$listaCocina = CCGetParam("lstCocina", array());
reset($listaCocina);
$tamano = sizeof($listaCocina);
//Manually Insert the relationships
$db = new clsDBdevelopment;
while(list($key, $ID_Cocina) = each($listaCocina)){
$SQL = "INSERT INTO tblcocinarestaurante (ID_Restaurante, ID_Cocina) VALUES(".$LastID.",".$ID_Cocina.") ";
$db->query($SQL);
}
$db->close;
its simple, add custom code to the after update and after delete to delete the relationships.
Happy Coding! =)
|
 |
 |
|