Custom Clone

QuestionsCustom Clone
Alfonso Cabrera asked 9 years ago

Hi Abu!

I would like to know how can I clone a row but I just want to insert some values of the selected row not all of them.

Example:

I have my employees table.

ID
Name
LastName
Address
City
State

I only want to copy in the new record the City and State of the row selected and leave the other columns with no information. How can I achieve this?

Thank you.

1 Answers
Abu Ghufran answered 9 years ago

You need to use custom clone function,

e.g.
$e["on_clone"] = array("custom_clone","null",false);
$g->set_events($e); // uncomment this to enable on_clone event

function custom_clone($data)
{
$src_id = $data["id"];
$f = $data["params"];

// here you can unset the $f["address"] and other fields.

$fields_str = implode(",",$f);
$sql = "INSERT INTO invheader ($fields_str) SELECT $fields_str FROM invheader WHERE id = $src_id";
mysql_query($sql);
}

Code: http://www.phpgrid.org/demo/demos/editing/clone-row.phps

Your Answer

9 + 6 =

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 0 / 5. Vote count: 0

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?