如何使用之间将简单的SQL查询转换为CodeIgniter?

时间:2019-05-10 05:23:00

标签: php sql codeigniter

请帮助我,我想将简单的SQL语句转换为Codeigniter

date($fromDate) BETWEEN vehicle_register.start_dt AND vehicle_register.end_dt

1 个答案:

答案 0 :(得分:2)

尝试使用Method chaining

$this->db->select('*');
$this->db->from('yourTableName');
$this->db->where('date('.$fromDate.') >=', 'vehicle_register.start_dt');
// >= will get conditional date too so please keep it as your reqirement
$this->db->where('date('.$fromDate.') <=', 'vehicle_register.end_dt');
$query= $this->db->get();
if($query->num_rows() > 0){
  //return $query->result();//according to your need
}else{
  //return array();//according to your need
}