Reputation: 393
The problem I'm having is with a strategy browser game which has 7 types of values. The problems are as follows:
$_POST
, from index unit_1 to index unit_7 included. These 7 values are INTEGERS between 0 and 20 and aren't static. They can at each call of the page. They represent the number of units sent."nameUnit" = "Soldier"
&& nbUnit = "0"
, "nameUnit" = "Mage"
&& nbUnit = "5"
, etc..Example of what I want to do :
UPDATE x SET nbUnit = $_POST['u1'] WHERE nameUnit = "Soldier", nbUnit = $_POST['u2'] WHERE nameUnit = "Mage" [...]
Is it possible to do this that way and can it be done in a single query?
Upvotes: 0
Views: 57
Reputation: 1405
IN PL SQL you can do the following :
UPDATE x SET nbUnit = case when nameUnit = "Soldier" then $_POST['u1']
when nameUnit = "Mage" then $_POST['u2'] else nbUnit end;
Upvotes: 0
Reputation: 466
this work in ur case
UPDATE x
SET nbUnit = $_POST['u1']
WHERE (nameUnit = "Soldier" AND nbUnit = $_POST['u2']) OR
(nameUnit = "Mage" AND nbUnit= $_POST['u5'])
Upvotes: 1