This topic is locked
[SOLVED]

 Tip Copy Child Records when Master Record is Copied

5/4/2012 9:39:54 PM
PHPRunner General questions
M
malnak author

Just trying to contribute. I wanted to copy child records when the master is copied I have an Orders Table and a Order_details table.
On the Orders table in the After Record Added Event include this code:



if ( $_SESSION["copyid1"]!=0)

{

// debbugging Echo "not equal zero";

global $conn;

$str = "select OrderID, ProductID, Quantity, CustCode from `order details` where OrderID =".$_SESSION["copyid1"];

$rs = db_query($str,$conn);

while($data = db_fetch_array($rs))

{

$strInsert = "insert into `order details` (OrderID, ProductID, Quantity, CustCode) VALUES ('".$values["OrderID"]."','".$data["ProductID"]."','".$data["Quantity"]."','".$data["CustCode"]."')";

db_exec($strInsert,$conn);

}

}

//header("Location: order_details_list.php?mastertable=orders&masterkey1=".$keys["OrderID"]);

//header("Location: order_details_list.php?mastertable=orders&masterkey1=" . $keys["OrderID"]);

// ********** Send simple email ************

$email=$_SESSION["emailID"];

$from="ordersdb@ACME.com";

$msg="Your Order has been received";

$subject="ACME Order Recieved";

//foreach($values as $field=>$value)

//{

// if(!IsBinaryType(GetFieldType($field)))

// $msg.= $field." : ".$value."\r\n";

//}
$ret=runner_mail(array('to' => $email, 'subject' => $subject, 'body' => $msg, 'from'=>$from));

if(!$ret["mailed"])

echo $ret["message"];
$_SESSION["copyid1"] = 0;


In the Add Page before Process have this code to flag for the copy:

if (@$_REQUEST["copyid1"])

$_SESSION["copyid1"] = $_REQUEST["copyid1"];


All praise to Sergey and Jane for their astonishing assistance.