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 WHERE
product_stocks.
stock_level= '> 1'
which is of course not correct. Can this be done?
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);
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.
I think this should do the trick:
$this->db->where('product_stocks.stock_level >', '1'); //moved the >
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With