CodeIgniter Forums
codeigniter 4.1.1 update +1 problem - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: codeigniter 4.1.1 update +1 problem (/showthread.php?tid=79261)



codeigniter 4.1.1 update +1 problem - amirodz - 05-19-2021

Code:
$AlertModel->set('read', 'read+1',false);
$AlertModel->where('user_id',$user_id);
$AlertModel->where('id',$id);
$AlertModel->update();
Do not add a number.
where is the problem.
codeigniter 4.1.1


RE: codeigniter 4.1.1 update +1 problem - iRedds - 05-19-2021

1. See the manual for how the update is performed.
https://codeigniter.com/user_guide/models/model.html#working-with-data

2. For increment, you can use increment() method
https://codeigniter.com/user_guide/database/query_builder.html#increment


RE: codeigniter 4.1.1 update +1 problem - amirodz - 05-19-2021

4.0.0 Work well


RE: codeigniter 4.1.1 update +1 problem - amirodz - 05-19-2021

$AlertModel->set('read', 'read+1',false);
$AlertModel->where('id',$id);
$AlertModel->update();

4.1.2 do not work It looks like there is a real problem


RE: codeigniter 4.1.1 update +1 problem - InsiteFX - 05-19-2021

Problem is your doing it wrong.

Did you even read the CodeIgniter Users Guide on the update method like @iRedds explained to you even gave you the links?

PHP Code:
// update method call
$userModel->update($id$data);

// increment column
$userModel->increment($column$value 1); 

I would sit down and read those to links very carefully.


RE: codeigniter 4.1.1 update +1 problem - amirodz - 05-20-2021

Thanks working well


RE: codeigniter 4.1.1 update +1 problem - includebeer - 05-20-2021

There's an example in the user guide almost identical to your code. But they are using the Query Builder functions. The Model class also call the query builder, so I'm not sure why it was not working for you.

From https://codeigniter.com/user_guide/database/query_builder.html#updating-data
PHP Code:
$builder->set('field''field+1'false);
$builder->where('id'2);
$builder->update();
// gives UPDATE mytable SET field = field+1 WHERE `id` = 2