开发者

How to write this query with codeigniter?

开发者 https://www.devze.com 2023-03-30 23:57 出处:网络
How to write select query with between similar to this with active record? SELECT * FROM test_tbl WHERE date BETWEEN \'$start\' and \'$end\' ORDER BY ID

How to write select query with between similar to this with active record?

SELECT * FROM test_tbl WHERE date BETWEEN '$start' and '$end' ORDER BY ID 

Re开发者_运维技巧gards


AFAIK, there's no built-in support for BETWEEN

You can do this instead

$this->db->where("date BETWEEN '$start' AND '$end'");
$this->db->get("test_tbl");  

Or write a helper function that look like this

function where_between($field, $min, $max){
     $CI = get_instance();
     return $CI->db->where("`$field` BETWEEN '$min' AND '$max'");
}  

Later on, you can use that function by calling it like where_between('test_tbl', $start, $end)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号