Skip to content

Instantly share code, notes, and snippets.

@nklatt
Created August 29, 2022 21:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nklatt/7d95734f9751cd9e632a89dc104c9302 to your computer and use it in GitHub Desktop.
Save nklatt/7d95734f9751cd9e632a89dc104c9302 to your computer and use it in GitHub Desktop.
PHP code that generates a MySQL query to copy rows from a table to the same table but with some column values changed.
$table = 'some_table';
$columns = implode(',', array(
'title',
'description',
'etc...',
));
$sql = '
INSERT INTO '.$some_table.' (product_id, '.$columns.')
SELECT "'.$destId.'", '.$columns.'
FROM '.$some_table.' WHERE product_id = "'.$origId->id.'"
';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment