in Education by
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? JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
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. $q = $dbc -> prepare("UPDATE accounts SET motivation = LEAST(motivation+100, maxMotivation)"); $q -> execute();

Related questions

0 votes
    Complete the sentence by choosing TWO WORDS either of which will fit the blank. The two words must both produce a ... on his bike. Select the correct answer from above options...
asked Nov 27, 2021 in Education by JackTerrance
0 votes
    I'm trying to enable Slow Query Logging on mysql 5.7 and getting this error: 2016-04-27T14:55:51 ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 11, 2022 in Education by JackTerrance
0 votes
    _________ refers to an undesirable state when a system attempts to perform two or more operations, which should, ... condition 2. Optimistic locking 3. Locking 4. Transaction...
asked Apr 12, 2021 in Technology by JackTerrance
0 votes
    One of the two events must happen. Given that the chance of one is two-third of the other, find the odds in favour of the other. Select the correct answer from above options...
asked Nov 22, 2021 in Education by JackTerrance
0 votes
    There are three coins. One is a two headed coin (having head on both faces), another is a based coin that ... the two headed coin? Select the correct answer from above options...
asked Nov 25, 2021 in Education by JackTerrance
0 votes
0 votes
    There are four machines and it is known that eactly two of them are faulty. They are tested, one by one, in a random ... . 1/2 D. 1/4 Select the correct answer from above options...
asked Nov 15, 2021 in Education by JackTerrance
0 votes
0 votes
    An urn contains 8 white and 4 red balls. Two balls are drawn from the urn one after the other without ... balls are white ? Select the correct answer from above options...
asked Nov 13, 2021 in Education by JackTerrance
...