【问题标题】:Active record for AND in code igniterCodeigniter 中 AND 的活动记录
【发布时间】:2014-10-01 09:08:15
【问题描述】:

如何在 codeigniter 的活动记录中编写此查询。

 SELECT * FROM `post_ads` WHERE `dates` >= '2014-09-20' AND `dates` <= '2014-09-22' ORDER BY `dates` ASC

我尝试了这段代码,但给出了一个空数组。

 $where = "DATE(dates) BETWEEN '2014-09-20' AND '2014-09-22'";
    $query = $this->db->where($where)->get('post_ads');
    return $query->result();

【问题讨论】:

标签: php mysql codeigniter


【解决方案1】:

像这样重复两次:

$this->db->select();
$this->db->from('post_ads');
$this->db->where('dates','2014-09-20');
$this->db->where('dates','2014-09-22');
$this->db->order_by('dates');

【讨论】:

    【解决方案2】:

    只要没有数组,你就可以试试这个 where 条件用 ; 分隔创建 AND 操作。

          $this->db->where('dates >=', 2014-09-20);
          $this->db->where('dates <=', 2014-09-22);
          $this->db->order_by("dates", "asc");
           $query = $this->db->get('post_ads');
          return $query->result();
    

    【讨论】:

      【解决方案3】:

      来自 codeigniter 教程:我的查询使用以下查询:

      $array = array('dates >=' => $to, 'dates <=' => $from); 
      $this->db->where($array);
      $this->db->order_by("dates", "asc"); 
      $query = $this->db->get('post_ads');
      return $query->result();
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-02-22
        • 2014-08-15
        • 2014-10-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多