Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Codeigniter Active record: greater than statement

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?

like image 421
stef Avatar asked Nov 09 '10 14:11

stef


People also ask

How use distinct in join query in CodeIgniter?

Distinct in Codeigniter Query Example: $where_array = array( 'email'=>'[email protected]', 'status'=>'1' ); $table_name = "users"; $limit = 10; $offset = 0; $this->db->distinct(); $query = $this->db->get_where($table_name,$where_array, $limit, $offset);

How do I print last query?

We can get last executed query using last_query() function of db class in codeigniter. It is a very simple to use $this->db->last_query() function to see SQL statements of last executed query in php codeigniter app.


2 Answers

I think this should do the trick:

$this->db->where('product_stocks.stock_level >', '1');  //moved the >
like image 144
JDM Avatar answered Oct 13 '22 22:10

JDM


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.
like image 40
Refazul Refat Avatar answered Oct 13 '22 21:10

Refazul Refat