Ver Mensaje Individual
  #16 (permalink)  
Antiguo 03/12/2010, 06:25
Avatar de arielcasanova
arielcasanova
 
Fecha de Ingreso: octubre-2004
Ubicación: Bahía Blanca - Argentina
Mensajes: 332
Antigüedad: 19 años, 6 meses
Puntos: 1
Respuesta: Duplicar registros

Venga, encontré esta función:

function DuplicateMySQLRecord ($table, $id_field, $id) {
// load the original record into an array
$result = mysql_query("SELECT * FROM {$table} WHERE {$id_field}={$id}");
$original_record = mysql_fetch_assoc($result);

// insert the new record and get the new auto_increment id
mysql_query("INSERT INTO {$table} (`{$id_field}`) VALUES (NULL)");
$newid = mysql_insert_id();

// generate the query to update the new record with the previous values
$query = "UPDATE {$table} SET ";
foreach ($original_record as $key => $value) {
if ($key != $id_field) {
$query .= '`'.$key.'` = "'.str_replace('"','\"',$value).'", ';
}
}
$query = substr($query,0,strlen($query)-2); # lop off the extra trailing comma
$query .= " WHERE {$id_field}={$newid}";
mysql_query($query);

// return the new id
return $newid;
}
__________________
Ariel Casanova
diseño y desarrollo web estratégico
www.emporia.com.ar