Created
August 29, 2022 21:52
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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