Welcome Guest, Not a member yet? Register   Sign In
db selection
#1

[eluser]Perkin5[/eluser]
I'm trying to select items from a db but I want to omit items that have a category of 'sold'. In the model I have tried this method:

Code:
function get_data(){
  $this->db->where('cat !=','sold');
  $results = $this->db->get('data')->result();
  return $results;
}

It sort of works but it also removes all items where 'cat' is null. Can't understand why that should be, if I leave out the 'where' condition, all items are selected including those with null fields.

I also tried this:

Code:
function get_data(){
  $sold = array('cat'=>'sold');
  $this->db->where($sold,false);
  $results = $this->db->get('data')->result();
  return $results;
}

but it then gets only the item where 'cat' is 'sold', the reverse of what I want.

Any advice appreciated.




Theme © iAndrew 2016 - Forum software by © MyBB