How to get Even / Odd id numbers from database table in codeigniter
I'm new to codeigniter and just folded into a query to solve a report for a crash project. Please help me the experts on Codeigniter.
- I have a large database table and only want to display even or even data rows from that table to be filtered by the table. The field is named "sale_id". I tried this in PHPMyadmin in raw coding and it worked for me. But it cannot be applied in Codeigniter.
SELECT * FROM ospos_pak_sub_cat WHERE id %2 =0;
Worked for me in raw PHP coding. How can I use it in Codeigniter. I used the Where clause already in this query and now I want to add a new query. Existing Where below is a condition that works fine.
$this->db->where('sale_date BETWEEN "'. $inputs['start_date']. '" and "'. $inputs['end_date'].'"');
It works and I tried the code below to get a solution that doesn't work and gets an error.
$this->db->where('sale_id %2'=> 0);
Getting error on this line. is talking -
Parse error: syntax error, unexpected '=>' (T_DOUBLE_ARROW)
Please help me find solutions. Thank you in advance.
source to share
in SQL, the% character is a wildcard and not a module that explains your error. you can use MOD function instead of http://dev.mysql.com/doc/refman/5.0/en/mathematical-functions.html#function_mod
so the resulting code will look like this:
$this->db->where('MOD(sale_id ,2) => 0');
source to share