Welcome Guest, Not a member yet? Register   Sign In
Database query with WHERE OR & AND
#1

[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?




Theme © iAndrew 2016 - Forum software by © MyBB