• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
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.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.