简体   繁体   中英

Greater than last login time from db

Okay, So I am wanting to get the new rows in a database since the last time the user had logged in.

The last login time is logged every time a user is logged in. It's stored in the database as a datetime .

The created date for the discussion is stored in the database as a datetime .

I need to take the last login time and compare it to the created time of the discussion. And return all the discussions that have been added since the last login of the logged in user.

In my model I tried doing this, but I got an error saying that I had an error in my sql.

$time is the last login time derived from the controller.

public function get_new($time)
{
    $query = $this->db->get_where('discussions', 'created <='.$time);

    return $query->result();
}

My controller has this code for calling the model.

$info = $this->aauth->get_user();

$time = $info->last_login;

$data['discussions'] = $this->discuss->get_new($time);

How can I get all new discussions that have been added since the last time the user logged in?

Try change your controller to this:

public function get_new($time)
{
    $query = $this->db->get_where('discussions', array('created <=' => $time));
    return $query->result();
}

I think you have to use where() instead of get_where() as per the documentation

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM