Welcome Guest, Not a member yet? Register   Sign In
Where Not Equal To
#1

[eluser]Hayezb[/eluser]
Okay, I for the life of me can not figure out why this will not work. I know it's something ridiculous that I must be missing.

Code:
function get_active_products() {

  $this->db->select('*');
  $this->db->from('CATALOGPRODUCTS');
  $this->db->where('STATUS !=' , 1);
  
  $query = $this->db->get();
  
  return $query->result();
}

This is returning nothing, but I have several rows of data that have STATUS set to NULL or 0. I've tried putting it in quotes and single tics. Everything. I can't use less than, greater than, etc... They all return nothing other than the standard EQUALs. It returns the rows where STATUS is set to 1.

#2

[eluser]boltsabre[/eluser]
You don't need this line of code, without it active records assumes you want everything, so you can leave it out.
Code:
$this->db->select('*');

Hmmm, at a quick glance your code looks okay.

A couple of things.

Have you tried putting 1 inside quotes like
Code:
$this->db->where('STATUS !=' , '1');

Or if you cannot get this working what about a lessthan operator like
Code:
$this->db->where('STATUS <' , 1);

Sorry, got to fly, hopefully this helps or someone else has an idea
#3

[eluser]Hayezb[/eluser]
[quote author="boltsabre" date="1394204960"]You don't need this line of code, without it active records assumes you want everything, so you can leave it out.
Code:
$this->db->select('*');

Hmmm, at a quick glance your code looks okay.

A couple of things.

Have you tried putting 1 inside quotes like
Code:
$this->db->where('STATUS !=' , '1');

Or if you cannot get this working what about a lessthan operator like
Code:
$this->db->where('STATUS <' , 1);

Sorry, got to fly, hopefully this helps or someone else has an idea[/quote]

Thank you for the reply!

I've tried both of those, and neither will work. I'm stumped.
#4

[eluser]CroNiX[/eluser]
Check the actual compiled query using $this->db->last_query().

I doubt it will make a difference, but you can also try <> for not equal.
#5

[eluser]Massaki[/eluser]
Are you sure that the table and the field names are on UPPERCASE? And what are the differences between NULL and 0? Can't you set the field as INT, and '0' by default?
#6

[eluser]Tpojka[/eluser]
Maybe good way should be using line:
Code:
$this->db->where_not_in('status', array('1'));

Also can be tried without array declaration, but just putting '1' as second parameter.
#7

[eluser]jonez[/eluser]
If you're fluent in SQL I'd skip active record for anything other than simple select or delete queries. It will do nothing but frustrate you.

Code:
$sql = "SELECT * FROM catalogproducts WHERE status <> 1";
$result = $this->db->query( $sql )->row_array( ); // for one
$results = $this->db->query( $sql )->result_array( ); // for rows

// using parameters for escaping if status is a variable
$sql = "SELECT * FROM catalogproducts WHERE status <> ?";
$result = $this->db->query( $sql, array( 1 ) )->row_array( );




Theme © iAndrew 2016 - Forum software by © MyBB