Pulkit Gaur

dream - do - deserve

MYSQL Clone records in same table

Filed under: PHP at 05:03:33 On 2007-05-09

While working on picporta we had one requirement where were supposed to clone records within the same table.

Searching in MYSQL manual i found INSERT-SELECT statement but it still does not supports same table Undecided


So did this quick hack in PHP ..


$tempTable = mysql_fetch_array(mysql_query("SELECT * FROM table." WHERE id='$passedId'),MYSQL_ASSOC) or die("Could not select record");
$result = mysql_query("INSERT INTO table (".implode(", ",array_keys($tempTable)).") VALUES ('".implode("', '",array_values($tempTable))."')");



Worked for me ..

3 Comment(s) | Add your own

Leave a Comment


Required, hidden