简体   繁体   English

大于上次从数据库登录的时间

[英]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 . 每次用户登录时,都会记录上次登录时间。它以datetime的形式存储在数据库中。

The created date for the discussion is stored in the database as a datetime . 为讨论创建的日期作为datetime存储在数据库中。

I need to take the last login time and compare it to the created time of the discussion. 我需要花费last login时间并将其与讨论的created时间进行比较。 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. 在我的模型中,我尝试执行此操作,但是出现一条错误消息,指出我的sql错误。

$time is the last login time derived from the controller. $time是从控制器派生的最后登录时间。

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 我认为您必须根据文档使用where()而不是get_where()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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