I have a MySQL Table as the image below:
I have my form edit as the image below:
(Path column on the Database selects the Category as on the image 2).
How do I run a multi-row MySQL Update query for this using PDO prepared statement.
I have a MySQL Table as the image below:
I have my form edit as the image below:
(Path column on the Database selects the Category as on the image 2).
How do I run a multi-row MySQL Update query for this using PDO prepared statement.
You can actually just use MySQL's CASE
to update multiple rows. This can be done for multiple columns as well, and the statements aren't that tough to generate in PHP.
UPDATE `links` SET `name` = CASE `link_id`
WHEN '36' THEN 'Mc'
WHEN '37' THEN 'Mc'
WHEN '38' THEN 'sdfghjkl'
WHEN '39' THEN 'r5tyuikolp;['
END, `path` = CASE `link_id`
WHEN '36' THEN '2'
WHEN '37' THEN '1'
WHEN '38' THEN '2'
WHEN '39' THEN '7'
END WHERE `link_id` IN ('36','37','38','39');