Codeigniter mysql where not equal to query

The Mysql codeigniter query does not work correctly. Suppose the mysql table looks like this:

 user_id|user_name
       1|john
       2|alex
       3|sam

Here username is unique

The following query should return false if username = john and user_id = 1 and true if say user_name = john and user_id = 2 .

$this->db->get_where('user', array('user_name' => $name,'user_id !=' => $userid));

But it returns true in case of username = john and user_id = 1 .

Can someone suggest me an alternative way to request non-equal.

print ($ this-> db-> last_query ()) gives:

SELECT * FROM () WHERE user_name = 'john' AND user_id!= '1'

+5
5

$this->db->query('your query');

+4

.

$total = 5;
$CI = get_instance();
$CI->load->database();
$CI->db->order_by('id','asc');
$topusers = $CI->db->get_where('users',array('user_type != 1  && `status` =' => 1),$total,0);
echo $CI ->db ->last_query();
die;

, @rohit: $this- > db- > query ('your query');

+1

$this -> db -> where('invitee_phone !=', $user_phone);
+1

1:

->where("column_name !=",$columnname) .

, , .

$whereArray = array(
                "employee_name" => $name,
                "employee_id !=" => $id,
        );

$this->db->select('*')->from('employee')->where($whereArray);

2:

, .

$thi->db->where(("employee_id =1 AND employee name != 'Gopi') OR designation_name='leader@gopis clan'");

2 , paranthesis "()"

0

:

$query = $this->db->select('*')->from('employee')->where('user_name', $name)->where('user_id !=', $userid)->get();
$last_query = $this->db->last_query();
$result = $query->result_array();

if you pass $ name = 'john' and $ userid = '1' then it returns an empty array.

0
source

All Articles