Dynamic Controller And Model (First Date,End Date)

Controller......

$FirstDate = date('Y-m-d', strtotime('-30 days')).' 00:00:01';
            $firstDateToFetch = date('Y-m-d', strtotime($FirstDate)) ;
            $endDateToFetch = '';
            $condition = array();
            $sales = $this->model->calculate('ppc_campaignspref',$firstDateToFetch,$endDateToFetch,$condition,'attributedSales30d','sales');


Model.......

public function calculate($tableName,$fromDate,$endDate=null,$condition,$column1=null,$asValue=null){
        $this->db->select("SUM(".$tableName.".".$column1.") as ".$asValue);//changed attributedSales1d) as Sales
        $this->db->from($tableName);
        (($fromDate!='')?$this->db->where('dayOfData >=', $fromDate) : '');
        (($endDate!='')?$this->db->where('dayOfData <=', $endDate) : '');
        if(!empty($condition)){
            $query = $this->db->where($condition); $this->db->get()->row_array();
        }else{
            $query = $this->db->get()->row_array();
        }
        return $query;
    }

Popular posts from this blog

SQL In Static Id Wise Record Skip After Show Result