CodeCharge Studio
search Register Login  

Visual PHP Web Development

Visually Create Internationalized Web Applications, Web Reports, Calendars, and more.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> PHP

 PHP insert into many-to-many link table

Print topic Send  topic

Author Message
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
View profile  Send private message
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! =)
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

Internet Database

Visually create Web enabled database applications in minutes.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.