CodeIgniter Forums
QB Class `increment() and `decrement()` don't work together - Printable Version

+- CodeIgniter Forums (
+-- Forum: CodeIgniter 4 (
+--- Forum: CodeIgniter 4 Support (
+--- Thread: QB Class `increment() and `decrement()` don't work together (/showthread.php?tid=80540)

QB Class `increment() and `decrement()` don't work together - bryson13 - 11-13-2021

Here's what I'm doing:

PHP Code:
if ($var1 == $var2) {
    $b $var2;
} else {
    $b $var1;
->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.