Multi Clone with custom insert

QuestionsMulti Clone with custom insert
Matt asked 2 weeks ago

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?

4 Answers
Abu Ghufran Staff answered 2 weeks ago

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.

_________________________
Abu Ghufran - Dev Team
Grid 4 PHP Framework
 
Matt answered 2 weeks ago

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);

}

Abu Ghufran Staff answered 2 weeks ago

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);
    }

}
_________________________
Abu Ghufran - Dev Team
Grid 4 PHP Framework
 
Matt answered 2 weeks ago

This works perfect, thank you!

Your Answer

4 + 1 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.



How useful was this discussion?

Click on a star to rate it!

Average rating 5 / 5. Vote count: 1

No votes so far! Be the first to rate it.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?