# Php/mysql update query

**URL:** <https://forum.kirupa.com/t/php-mysql-update-query/288431>\
**Category:** Uncategorized\
**Created:** [May 15, 2009, 3:27pm UTC](https://forum.kirupa.com/t/php-mysql-update-query/288431 "2009-05-15T15:27:10Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nevo](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/nevo/32/3473_2.png) [@Nevo](https://forum.kirupa.com/u/Nevo)\
**Post date:** [May 15, 2009, 3:27pm UTC](https://forum.kirupa.com/t/php-mysql-update-query/288431/1 "2009-05-15T15:27:10Z")

</div>

Hi,

Thanks in advance for a solution 🙂

I’m sure I must have written something to do this in the past but I guess I’m having a mind blank.

I’m tying to write a query to update multiple columns in multiple rows in a MySQL table.

```auto

$update = $db->update("UPDATE ter SET 
                      ari = case id 
                            when '$sql->terr1' then (ter.ari-$move) 
                            when '$sql->terr2' then (ter.ari+$move)
                      end
                      WHERE id in ('$sql->terr1', '$sql->terr2')");
return "true";

```

The above works fine for updating a single column in multiple rows but I need to update multiple rows in multiple columns

I’ev played around like

```auto

$update = $db->update("UPDATE ter SET 
                          ari = case id when '$sql->terr1' then (ter.ari-$move) when '$sql->terr2' then (ter.ari+$move) end
                          name = case id when '$sql->terr1' then (ter.name-'test') when '$sql->terr2' then (ter.name+'test) end 
                          WHERE id in ('$sql->terr1', '$sql->terr2')");
      return "true";

```

Been looking at it for a while and done a lot of googling but totally stumped. I’m slowly coming to the conclusion it’s not possible but I like to think nothing is impossible when it comes ot MySQL 🙂

Any help would be appreciated as I have about 25 queries to write… with 2 or 3 fields in each that’s 60+ queries ☹

Oli
