phpcodeigniterwhere-clausequery-builder

CodeIgniter query builder script WHERE column value does not equal a PHP value


If this query for select all records where id = 11:

 $this->db->select('title')->from('mytable')->where('id', $id)->limit(10, 20);
 $query = $this->db->get();

then what is the query to select all records where id != 11 in CodeIgniter style?


Solution

  • Just add it to the column part of the where, so

    $this->db->select('title')->from('mytable')->where('id !=', $id)->limit(10, 20);
    $query = $this->db->get();
    

    Btw, always check the codeigniter manual, it mentions it right with the where() documentation and it's one of the best documentations you are ever going to find.