Welcome Guest, Not a member yet? Register   Sign In
codeigniter 4.1.1 update +1 problem
#1

(This post was last modified: 05-19-2021, 07:39 AM by amirodz.)

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
Reply
#2

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

2. For increment, you can use increment() method
https://codeigniter.com/user_guide/datab...#increment
Reply
#3

4.0.0 Work well
Reply
#4

$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
Reply
#5

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.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#6

Thanks working well
Reply
#7

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/datab...ating-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 
CodeIgniter 4 tutorials (EN/FR) - https://includebeer.com
/*** NO support in private message - Use the forum! ***/
Reply




Theme © iAndrew 2016 - Forum software by © MyBB