Welcome Guest, Not a member yet? Register   Sign In
count # logins
#1

Trying to have a track of how many times a user logges in. And there is a function in mysql increase a db value by a number.
But how do i achieve this with use of codeigniter model?
Have tried:
PHP Code:
$newdata = [
                    'bruker_id' => $bruker['bruker_id'],
                    'lastlogin' => $lastlogin,
                    'logins' => '\'logins+1\''// have also tried 'logins+1'
                ];

                $add_lastlogin $model->save($newdata); 
But the "logins" column in the db is not updated...
Logins set as INT(11) in Mysql

Bengt
Reply
#2

first, dont forget to check $allowedFields in your model.
then, u can do this :
Code:
$model->where('bruker_id', $bruker['bruker_id'])
            ->set('logins', '`logins`+1', FALSE)
            ->update();
Reply
#3

(06-13-2021, 03:40 PM)muhammadrejeki Wrote: first, dont forget to check $allowedFields in your model.
then, u can do this :
Code:
$model->where('bruker_id', $bruker['bruker_id'])
            ->set('logins', '`logins`+1', FALSE)
            ->update();

Thanx.. Works great...

Bengt
Reply




Theme © iAndrew 2016 - Forum software by © MyBB