I have two queries like so,
$q = $dbc -> prepare("UPDATE accounts SET motivation = motivation+100 WHERE motivation <= maxMotivation-100");
$q -> execute();
$q = $dbc -> prepare("UPDATE accounts SET motivation = maxMotivation WHERE motivation > maxMotivation-100");
$q -> execute();
It basically ensures that a number cannot go over the max number allowed. But the problem is that it is going into a cronjob, so how can I do this in one statement? If the first fails then do the second or if the first succeeds skip the second. Is there a way with mysql if statements?
You don’t need to do this in two queries. It looks like you’re adding 100 to each motivation value in the table; if that puts you over the maxMotivation, then use that value. That can be done in one shot with no WHERE clause.