Not equal to condition in mysql query codeigniter

This code of my model:

    public function select($id)
    {           
        $this->db->select('Something');    
        $this->db->from('tbl_somthing');
        $this->db->where('tbl_somthing.User_id',$id);
        $this->db->where('tbl_somthing.Something',0,FALSE);
        $query = $this->db->get();
        return $query->result();
    }

How can I select only non-zero values ​​from the Something field? The above request does not work.

+5
source share
4 answers

Try the following:

public function select($id){

        return $this->db->select('Something');    
                    ->from('tbl_somthing');
                    ->where('tbl_somthing.User_id',$id);
                    ->where('tbl_somthing.Something != ',0,FALSE);
                    ->get()->result();
    }
+13
source

Try this

We can simply use the method to find out the unequal value from the mysqli codeigniter query:

$this->db->where('tbl_tabel_name != ', $id_name);  //correct way
+3
source

This will also work nicely:

    <?php
     $my_query = $this->db->get_where('my_table' , array(
                           'table_row!='=> NULL
    ))->result_array();
    ?>

Enjoy :)

+1
source

also done using

$this->db->where('columnName !=','string');
0
source

Source: https://habr.com/ru/post/1607955/


All Articles