-1

I have a MySQL Table as the image below: enter image description here

I have my form edit as the image below: enter image description here

(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.

OmniPotens
  • 1,125
  • 13
  • 30
  • possible duplicate of [Multiple Updates in MySQL](http://stackoverflow.com/questions/3432/multiple-updates-in-mysql) – jli Aug 05 '13 at 19:19
  • YES, they are dependent on WHERE link_id IN (...). Something of that nature. @jli I guess you should check to see if they have PDO on just MySQL on them before you mark down. – OmniPotens Aug 05 '13 at 19:23

1 Answers1

1

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');
theftprevention
  • 5,083
  • 3
  • 18
  • 31
  • Thanks for the lead. Assuming I am to run this same query to loop through like 1000 rows, how do I go about running the loop and then this query to achieve the same result as this example's solution you've provided. – OmniPotens Aug 05 '13 at 20:47