Welcome Guest, Not a member yet? Register   Sign In
QB Class `increment() and `decrement()` don't work together
#1

Here's what I'm doing:

PHP Code:
if ($var1 == $var2) {
    $b $var2;
} else {
    $b $var1;
    $diffModel->doChange($id$var1); 
    $model
->where(['id' => $var2])->decrement('cnt');
    $model->where(['id' => $var1])->increment('cnt');


No matter what I try, it will only either increment or decrement, usually the first in order, but not both.

For reference, my use case is moving an item from one group to another, and it's more efficient to store the total count of items in each group as a column. So, I'm decreasing the count of one group's items while increasing the count of the other.

Searched the forums and Google and found nothing. The docs on these two methods aren't much help. I've tried using `settype()` and `intval()` since both values are strings in the code and going into an int field in MySQL. I've tried changing the order of the statements. I've tried separating the statements with other functions. Still, only one will work. Help? TIA.

CI 4.1.4. PHP 7.4. Xampp running on Windows 10. Development mode.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB