【问题标题】:How to get data according to timestamps in codeigniter?如何根据codeigniter中的时间戳获取数据?
【发布时间】:2018-11-08 09:29:22
【问题描述】:

我有一个表调用在数据库中查看了如下所示的书籍

book_id     user_uniq_id   date
3           111111         2018-11-06 00:29:15

这么多行我需要根据日期获取 book_id 和 user_uniq_id

例如,在这一天,这些用户是这样看这些书的

如何在 codeigniter 中为此编写 sql 查询

【问题讨论】:

  • 您的问题不清楚...您能否尝试添加另一个示例来解释所需的输出和多个输入示例?
  • 你可以使用beetweenmaybe this will help
  • 它很清楚,但在答案中需要足够的细节。不具体。
  • $results = $this->db->order_by('date' 'DESC')->get('viewed_books')->result();

标签: php sql codeigniter


【解决方案1】:

我不确定你的问题是否足够清楚,但从我得到的信息来看,你想要一个基于时间戳的查询,那么你应该试试这个。

$timestamp = '2018-11-06 00:29:15';

$this->db->select('book_id, user_uniq_id');

$query = $this->db->get_where('table', array('date' => '>' . $timestamp));

【讨论】:

    【解决方案2】:
    $sql = "SELECT book_id, user_uniq_id from viewed_books ORDER BY date";
    $query = $this->db->query($sql);
    $bookData= $query->result_array();
    

    你可以看到你的结果

    var_dump($bookData);
    

    希望这是你寻求的答案

    【讨论】:

      猜你喜欢
      • 2020-03-07
      • 1970-01-01
      • 2020-11-18
      • 1970-01-01
      • 2011-10-29
      • 1970-01-01
      • 1970-01-01
      • 2015-09-03
      • 2018-04-28
      相关资源
      最近更新 更多