使用 CodeIgniter 框架。如何 get_where 但将结果限制为过去 12 小时?

Using CodeIgniter framework. How to get_where but limit the results to the past 12 hours?

基本上我有一个完整的数据库 table 专门用于用户提交。每行都有一个 timestamp 列,这是用户提交时的 php time()username 列,我用它来过滤 table一个特定的用户名。

但是用户名有多行(假设超过 9000 行)。

如何进一步过滤到过去 12 小时?这是 43200 seconds

我怎样才能有效地做到这一点?

我似乎找不到可以通过 BETWEEN nownow - 43200

之类的东西来限制结果的 CodeIgniter db query 函数

我必须注意 timestamp 字段的类型是 BIGINT(20) 并且它存储 PHP 时间戳 time()

使用下面的查询

SELECT * FROM reports WHERE username = "username" and `Date` > NOW() - INTERVAL 12 HOUR

在 codeigniter 中

$this->db->query("SELECT * FROM reports WHERE username = "username" and `Date` > NOW() - INTERVAL 12 HOUR")->result_array();

只需使用 where 子句 where("timestamp_column <=",$time);

 $time =time()-43200;
 $this->db->select("colum1,column2");
 $this->db->where("timestamp_column >=",$time);
 $this->db->from("tabl_name");
 $result = $this->db->get()->result();