20

I'm trying to convert a "greater than" where statement to CI's Active Record syntax. When I use this snippet

    $this->db->join('product_stocks', "product_stocks.size_id_fk = product_attributes.id", "left");
    $this->db->where('product_stocks.stock_level', '> 1');      
    $result = $this->db->get('product_attributes')->result_array();

Then print $this->db->last_query(); shows WHEREproduct_stocks.stock_level= '> 1' which is of course not correct. Can this be done?

3 Answers 3

73

I think this should do the trick:

$this->db->where('product_stocks.stock_level >', '1');  //moved the >
Sign up to request clarification or add additional context in comments.

Comments

7

Either

$this->db->where('product_stocks.stock_level >', '1');
or
$this->db->where(array('product_stocks.stock_level >'=>'1'));
should do it. Note the space between the field name and the operator; otherwise you will end up getting Error 1064.

Comments

5

You Can also Pass a String parameter to where() function like this,

$this->db->where('product_stocks.stock_level > 1');

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.