hi i am using codeigniter , and i have a table like this

i want to get all records where PreferenceID value is not in PreferenceParentID column
in this case i am fitering table also with the EntityID . and PreferenceParentID shoul be != 0
suppose i filter by entityID 53
my results shoul be
Couture , Denims
because PreferenceID is not in PreferenceParentID in both cases . i tried with where_not_in() but could not do . please help
this is my query
$table = $this->mastables['shop_profile_preferences'];
$this->db->select('a.ProfilePreferenceID');
$this->db->from($table." as a");
$where2 = "(SELECT a.PreferenceParentID FROM ".$table.")";
$this->db->where_not_in('a.PreferenceID', $where2);
$this->db->where("a.EntityID",$shop_id);
$this->db->where('a.PreferenceParentID !=',0);
$query=$this->db->get();
if($query->num_rows()>0)
{
return $query->result_array();
}
else
{
return FALSE;
}
the result of my query is
Array
(
[0] => Array
(
[ProfilePreferenceID] => 274
)
[1] => Array
(
[ProfilePreferenceID] => 275
)
[2] => Array
(
[ProfilePreferenceID] => 276
)
)
how to use where_not_in() properly . or ids there any other methods . please help …..
thanks in advance .
UPDATE
$table = $this->mastables['shop_profile_preferences'];
$this->db->select('a.ProfilePreferenceID,a.ProfilePreferenceValue');
$this->db->from($table." as a");
$this->db->where('a.PreferenceParentID !=',0);
$this->db->where('a.PreferenceID NOT IN (SELECT a.PreferenceParentID FROM '.$table.')', NULL, FALSE);
$this->db->where("a.EntityID",$shop_id);
$query=$this->db->get();
if($query->num_rows()>0)
{
return $query->result_array();
}
else
{
return FALSE;
}
You can’t do that with CodeIgniter’s
where_not_in(). Because the second argument is supposed to be an array and not a string like that.What you can do is instead use the usual
where()method.In case you’re wondering, the third argument in the code above is to prevent CodeIgniter from trying to protect the field and table name with backticks.