Between Method

Between is a method of the DB object in the model class to be used as a Query Builder . The purpose of this method is to filter data that is compatible with the BETWEEN command in SQL.

<?php
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);
  }

  /**
  * Get blog post by creation date (not date time)
  * @param  string  $sdate  		String date format YYYY-MM-DD
  * @param  string  $edate  		String date format YYYY-MM-DD
  * @return array           		Result array of object
  */
  public function getByDateRange($sdate,$edate){
    if (strlen($sdate)==10 && strlen($edate)==10) {
      $this->db->between("$this->tbl_as.cdate", "'$sdate'", "'$edate 23:59:59'");
    }elseif(strlen($sdate)==10 && strlen($edate)!=10){
      $this->db->where_as("$this->tbl_as.cdate", "'$sdate'", "AND", '<=');
    }elseif(strlen($sdate)!=10 && strlen($edate)==10){
      $this->db->where_as("$this->tbl_as.cdate", "'$edate'", "AND", '>=');
    }
    return $this->db->get();
  }

  /**
  * Get blog post by publish date time
  * @param  string  $sdate  		String date format YYYY-MM-DD
  * @param  string  $edate  		String date format YYYY-MM-DD
  * @return array           		Result array of object
  */
  public function getByDateTimeRange($sdate,$edate){
    if (strlen($sdate)==10 && strlen($edate)==10) {
      $this->db->between("$this->tbl_as.pubdt", "('$sdate 00:00:00')", "('$edate 23:59:59')");
    }elseif(strlen($sdate)==10 && strlen($edate)!=10){
      $this->db->where_as("$this->tbl_as.pubdt", "('$sdate 00:00:00')", "AND", '<=');
    }elseif(strlen($sdate)!=10 && strlen($edate)==10){
      $this->db->where_as("$this->tbl_as.pubdt", "('$edate 23:59:59')", "AND", '>=');
    }
    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->between( COLUMN_NAME, VALUE_FROM, VALUE_TO): $this->db

COLUMN_NAME

Column name required for filtering data from table. The columname should exist on selected table. This method has automatically escaped.

VALUE_FROM

Value required for matched with data against COLUMN_NAME.

VALUE_TO

Value required for matched with data against COLUMN_NAME.

Tips

This method can be chained with other Query Builder methods, because it returns the same object value (return object) as $this->db in the class Model.