php – 在WHERE条件下使用BETWEEN

前端之家收集整理的这篇文章主要介绍了php – 在WHERE条件下使用BETWEEN前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想要以下功能来选择具有特定$minvalue和$maxvalue之间的住宿的酒店.什么是最好的方式呢?
  1. function gethotels($state_id,$city,$accommodation,$minvalue,$maxvalue,$limit,$pgoffset)
  2. {
  3. $this->db->limit($limit,$pgoffset);
  4. $this->db->order_by("id","desc");
  5. $this->db->where('state_id',$state_id);
  6. $this->db->where('city',$city);
  7.  
  8. // This one should become a between selector
  9. $this->db->where($accommodation,$minvalue);
  10.  
  11. $result_hotels = $this->db->get('hotels');
  12. return $result_hotels->result();
  13.  
  14. }
你应该使用
  1. $this->db->where('$accommodation >=',minvalue);
  2. $this->db->where('$accommodation <=',maxvalue);

我不确定语法,所以如果不正确,请求赦免.
无论如何,BETWEEN使用> = min&&&& < =最大
这是我的例子的意思.

编辑:
看着this link我想你可以写:

  1. $this->db->where("$accommodation BETWEEN $minvalue AND $maxvalue");

猜你在找的PHP相关文章