search

Home  >  Q&A  >  body text

Less than or equal to using mysql in codeigniter does not work

I have a simple query that looks like this:

$backlogs=$_POST['backlogs'];

$this->db->select('*');
if(!empty($backlogs)) {
  $this->db->where('backlogs >=', $backlogs-3);
  $this->db->where('backlogs >=', $backlogs+3);
}
$query  =   $this->db->get('universities');

I want the query to get values ​​greater than or equal to 3 values ​​and less than or equal to but I am not getting the results I want, for example if I give the value 12 I need the values ​​in 9 to 15 but it I was given some random values ​​like up to 25 etc, can anyone tell me how to solve this problem

P粉445714413P粉445714413255 days ago319

reply all(1)I'll reply

  • P粉055726146

    P粉0557261462024-03-23 00:16:33

    Change the code to this. You have two >=, so if you have 12, backlog >= 9 and backlog >= 15, so all 9+ are matched.

    $this->db->where('backlogs >=', $backlogs-3);
    $this->db->where('backlogs <=', $backlogs+3);

    reply
    0
  • Cancelreply