Currently I am using a custom clone function to select a record base on the ID selected and inserting the record to a second table. Is there a way to have it select and insert multiple records based on the rows chosen?
Currently if I try to clone more than one it gives an incorrect syntax near ‘,’ as the select is pulling back multiple ID’s separated by a comma. Is it possible to have it do an insert to the second table for each record chosen on the first?
As you are using custom clone function and getting comma sep ids, you can:
1) $ids = explode(“,”,$id)
2) iterate foreach for $ids
3) perform insert operation in foreach loop based on iterated id.
If it does not help, please share code for review.
A little more clarification would be helpful please. Here is my code, (shortened query to make it cleaner):
$e[“on_clone”] = array(“custom_clone”,null,false);
$g->set_events($e);
function custom_clone($data)
{
global $g;
$src_id = $data[“ID”];
$Submitted_By=$Login_ID;
$Status=‘New’;
$sql = “INSERT INTO System_Tickets (Submitted_By, Status, System, OS, Issue_Type, Submitted) SELECT ‘$Submitted_By’ AS Submitted_By, ‘$Status’ AS Status, System, OS, Issue_Type, GETDATE() AS Submitted FROM Triage_List WHERE ID = $src_id”;
$g->execute_query($sql);
}
I mean something like this, given that $data[“ID”] contains comma sep ids like 1,2,3
function custom_clone($data) { global $g; $ids = $data["ID"]; $ids = explode(",",$ids); foreach($ids as $src_id) { $Submitted_By=$Login_ID; $Status='New'; $sql = "INSERT INTO System_Tickets (Submitted_By, Status, System, OS, Issue_Type, Submitted) SELECT '$Submitted_By' AS Submitted_By, '$Status' AS Status, System, OS, Issue_Type, GETDATE() AS Submitted FROM Triage_List WHERE ID = $src_id"; $g->execute_query($sql); } }