在 WHERE 条件下使用 BETWEEN [英] using BETWEEN in WHERE condition
本文介绍了在 WHERE 条件下使用 BETWEEN的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想要以下函数来选择住宿在某个 $minvalue
和 $maxvalue
之间的酒店.这样做的最佳方法是什么?
I'd like the following function to select hotels with an accomodation between a certain $minvalue
and $maxvalue
. What would be the best way to do that?
function gethotels($state_id,$city,$accommodation,$minvalue,$maxvalue,$limit,$pgoffset)
{
$this->db->limit($limit, $pgoffset);
$this->db->order_by("id", "desc");
$this->db->where('state_id',$state_id);
$this->db->where('city',$city);
// This one should become a between selector
$this->db->where($accommodation,$minvalue);
$result_hotels = $this->db->get('hotels');
return $result_hotels->result();
}
推荐答案
你应该使用
$this->db->where('$accommodation >=', minvalue);
$this->db->where('$accommodation <=', maxvalue);
我不确定语法,所以如果它不正确,请原谅.
无论如何 BETWEEN
是使用 >=min && 实现的<=最大值
这就是我的例子的意思.
I'm not sure of syntax, so I beg your pardon if it's not correct.
Anyway BETWEEN
is implemented using >=min && <=max.
This is the meaning of my example.
已
看着这个链接,我想你可以写:
$this->db->where("$accommodation BETWEEN $minvalue AND $maxvalue");
这篇关于在 WHERE 条件下使用 BETWEEN的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文