using BETWEEN in WHERE condition

前端 未结 6 1898
萌比男神i
萌比男神i 2020-12-09 04:26

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

相关标签:
6条回答
  • 2020-12-09 04:36

    You should use

    $this->db->where('$accommodation >=', minvalue);
    $this->db->where('$accommodation <=', maxvalue);
    

    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.

    EDITED:
    Looking at this link I think you could write:

    $this->db->where("$accommodation BETWEEN $minvalue AND $maxvalue");
    
    0 讨论(0)
  • 2020-12-09 04:36

    Sounds correct but some issues maybe creates executing this query: I would suggest:

    $this->db->where( "$accommodation BETWEEN $minvalue AND $maxvalue", NULL, FALSE );
    
    0 讨论(0)
  • 2020-12-09 04:51

    $this->db->where('accommodation BETWEEN '' . $sdate . '' AND '' . $edate . ''');

    this is my solution

    0 讨论(0)
  • 2020-12-09 04:52

    In Codeigniter This is simple Way to check between two date records ...

    $start_date='2016-01-01';
    $end_date='2016-01-31';
    
    $this->db->where('date BETWEEN "'. date('Y-m-d', strtotime($start_date)). '" and "'. date('Y-m-d', strtotime($end_date)).'"');
    
    0 讨论(0)
  • 2020-12-09 04:54

    You might also encounter an error message. "Operand type clash: date is incompatible with int.

    Use single quotes around the dates. E.g.: $this->db->where("$accommodation BETWEEN '$minvalue' AND '$maxvalue'");

    0 讨论(0)
  • 2020-12-09 04:54

    I think we can write like this : $this->db->where('accommodation >=', minvalue); $this->db->where('accommodation <=', maxvalue);

    //without dollar($) sign It's work for me :)

    0 讨论(0)
提交回复
热议问题