Between Method
Between method is part of database class builder for filtering data compatible with BETWEEN Clause on SQL. This method support chained, and has flow from top to bottom while bracket are used.
class Blog_Model extends SENE_Model{ var $tbl = 'd_order'; var $tbl_as = 'dor'; public function __construct(){ parent::__construct(); $this->db->from($this->tbl,$this->tbl_as); } public function getById($id){ $this->db->where("id",$id,"AND","=",0,0); return $this->db->get_first(); } public function getCancel(){ $this->db->where("order_status","order_cancel","AND","=",0,0); return $this->db->get(); } public function getCancelByUser($b_user_id){ $this->db->where("order_status","order_cancel","AND","=",0,0) $this->db->where("b_user_id",$b_user_id,"AND","=",0,0); return $this->db->get(); } }
Parameters
Where method has 2 required parameters that is column name and value, another parameters are optional. Here is the completed parameters can be used by where methods
$this->db->where( COLUMN_NAME, VALUE, " AND | OR ", "= | != | <= | >= | < | > | <> | like | like% | %like | %like% | notlike | notlike% |%notlike | %notlike% ", OPENBRACKET, CLOSEBRACKET );
COLUMN_NAME
Column name required for filtering data from table. The columname should exist on selected table. This method has automatically escaped.
VALUE
Value required for matched with data on table. This method has automatically escaped.
Combining Method
Default value is AND, this parameter useful for filtering data for multiple condition. Available value AND or OR. Value of this parameter is not case sensitive.
Relational Operator
Value required for matched COLUMN_NAME with value. Available value:
- =
- <
- >
- <=
- >=
- <>
- like
- like%
- %like
- %like%
- notlike
- notlike%
- %notlike
- %notlike%
Value of this parameter is not case sensitive.
OPEN BRACKET
Required for adding bracket for prioritize condition filtering, default value 0. Available value 1 and 0.
CLOSE BRACKET
Required for adding bracket for prioritize condition filtering, default value 0. Available value 1 and 0.
Example usage
Here is the examples using where method, makes sure another from method and get method has executed for real result. See the first of this page for full example.
Basic example
SELECT * FROM d_order WHERE `id` = 1
$this->db->where("id",1);
Using AND / OR
SELECT * FROM d_order WHERE `a_company_id` = 1 OR `b_user_id` = 1
$this->db->where("b_user_id",1,'OR')->where("a_company_id",1,'AND');
Using Relational Operator
SELECT * FROM d_order WHERE `b_user_id` = 1 AND `grand_total` >= 1000 AND `status_text` LIKE 'order_completed'
$this->db ->where("b_user_id",1) ->where("grand_total",1000,"and",'>=') ->where("status_text",'order_completed',"and",'like');
Using Bracket
SELECT * FROM b_user WHERE `status_text` LIKE 'active' AND ( `fname` LIKE '%andre%' OR `lname` LIKE '%andre%' OR `city` LIKE '%andre%' OR `email LIKE '%andre%' )
$this->db ->where("status_text",'active','and','like') ->where("fname",'andre',"and",'%like%',1,0) ->where("lname",'andre',"and",'%like%',0,0) ->where("city",'andre',"and",'%like%',0,0) ->where("email",'andre',"and",'%like%',0,1);
Advanced Where Condition
Seme Framework has advanced where method called where_as method.