CodeIgniter Forums
WHERE is not working. - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Development (https://forum.codeigniter.com/forumdisplay.php?fid=6)
+--- Forum: CodeIgniter 2.x (https://forum.codeigniter.com/forumdisplay.php?fid=18)
+--- Thread: WHERE is not working. (/showthread.php?tid=868)



WHERE is not working. - jaysondotp - 01-24-2015

Hi

i have the following code below that mysql WHERE FUNCTION Is NOT WORKING whine i use OR_LIKE. but whine i try to remove allĀ OR_LIKE it well work perfect.

Code:
$this->db->select('users.*,query1.*,query_price.*,');
$this->db->from('query_price');
$this->db->join('query1','query1.Barcode = query_price.Barcode', 'left');
$this->db->join('users','query_price.username = users.username', 'left');
$this->db->order_by('query_price.price_id','desc');
    
$this->db->where('query_price.approve !=',''); // THIS IS NOT WORK //

$this->db->like('query1.description',$search_keyword);
$this->db->or_like('query_price.Barcode',$search_keyword);
$this->db->or_like('query_price.new_cost',$search_keyword);
$this->db->or_like('query_price.new_dp',$search_keyword);
$this->db->or_like('query_price.new_srp',$search_keyword);
$this->db->or_like('query_price.new_reg',$search_keyword);
$this->db->or_like('query_price.dis_a',$search_keyword);
$this->db->or_like('query_price.dis_b',$search_keyword);
$this->db->or_like('query_price.date',$search_keyword);
$this->db->or_like('query_price.prepare',$search_keyword);

i try different methods but im NOT luck, and im hoping that i get the answer here.

Thanks in advance..


RE: WHERE is not working. - sv3tli0 - 01-24-2015

Sorry but I can't test at moment so only can give you idea..
Try replacing first like with or_like ..
When you have where cause already it must be or_like..

(to be sure echo $this->db->last_query(); after the query to see what sql query is generated.. )


RE: WHERE is not working. - Rufnex - 01-24-2015

Try this

PHP Code:
$this->db->where('query_price.approve !=',''false); 



RE: WHERE is not working. - ivantcholakov - 01-24-2015

@jaysondotp Are you trying this on CodeIgniter 3?

Edit: Watch the parentheses control.

IMO

CI2: You need to switch to raw SQL with proper escaping.

CI3: You need to correct the query builder code by using group_start(), and group_end() methods (variations *_group_start() if needed). See http://www.codeigniter.com/userguide3/database/query_builder.html?highlight=group_start#CI_DB_query_builder.group_start

Check what SQL actually is generated and whether it is as you expected to be.

Edit 2:

Examples: http://www.codeigniter.com/userguide3/database/query_builder.html#query-grouping