![]() |
Database query with WHERE OR & AND - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Database query with WHERE OR & AND (/showthread.php?tid=47900) |
Database query with WHERE OR & AND - El Forum - 12-27-2011 [eluser]Unknown[/eluser] Hi, today I want to select some records from my db table which name is products. I try to select with OR & AND. However I get all of my records from my table. My query builded like this, $this->db->where(array('products_ISDELETED'=>'N'));//Select which is not sign with deleted $this->db->or_where(array('productscategory_PARENT'=>1,'productscategory_ID'=>1));//select only in this category1 and subcategory which category's parent is category1 $this->db->join(array('productscategory','productscategory_ID=products_category_ID','LEFT')); $result=$this->db->get('products'); "SELECT * FROM products LEFT JOIN productscategory ON products_category_ID=productscategory_ID WHERE products_ISDELETED='N' AND productscategory_PARENT=1 OR productscategory_ID=1" When I run this part of query it gave me the products which are under category1 But I want to take which are under category1 and not deleted like this "SELECT * FROM products LEFT JOIN productscategory ON products_category_ID=productscategory_ID WHERE products_ISDELETED='N' AND (productscategory_PARENT=1 OR productscategory_ID=1)" is this BUG? if not can anyone say how I can do this with CI? |