#
#
# artur #2015-04-22 03:21:53
Kohana
# artur #, 2015-04-22 03:21:53

How to do multiple UPDATE using Query Builder?

Hello!
Does anyone know how to do multiple UPDATE?
Right now I'm doing this:

foreach ($users as $u) {
            $update = DB::update('users_table');
            $update->set(array('rank' => DB::expr('rank + ' . $u['rank'])))
                    ->where('id', '=', $u['id']);
            $update->execute();
        }

- but it's full of tin ...
Can I somehow update the RANK of individual users in one request? The catch here is that in $users there is a separate RANK for each user ID ...
Please help

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vyacheslav Plisko, 2015-04-22
@AmdY

If the changes are by the same number, then it’s just worth using whereIn, if it’s different, then you should leave it like that. In sql, this is done through constructs like
In a loop, the request is clearer.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question