i got an error when array values pass to view page from controller.
my code as below :
$a[$month] = $ii; //Getting an Array values
$data['values']=$a; //Passing array values to view page as declared as $data
My Controller function:
function reports()
{
if($this->input->post('getit'))
{
$pro_id=$this->input->post('product').'<br>';
$fdate= date('d', strtotime($this->input->post('from')));
$fmonth = date('m', strtotime($this->input->post('from')));
$tdate = date('d', strtotime($this->input->post('to')));
$tmonth = date('m', strtotime($this->input->post('to')));
$year= $this->input->post('year');
$data = $this->model_select->date_range($fdate,$fmonth,$tdate,$tmonth,$year);
$ii=0;
foreach ($data->result() as $dat){
$dat->order_id;$month=date('m', strtotime($dat->order_date));
$where=array('order_id'=>$dat->order_id,'pr_id'=>$pro_id);
$aabb=$this->model_select->select_where($where,'order_products');
if($aabb->num_rows()!=0){
foreach($aabb->result() as $res){ $ii++; }
}//-----forech end
$a[$month] = $ii;
}
$data['values']=$a;
$this->load->view('admin/reports',$data);
}
$data
passing view page as follows:
$this->load->view('admin/reports',$data);
error mentioned when controller load that function, that line as below:
$data['values']=$a; //error mention this line as below
error as :
Fatal error: Cannot use object of type CI_DB_mysql_result as array in controllers\admin.php on line 1286
i make mistake in my code means. please help me.
$data
? – sgt 2 hours ago->result()
? – Ghost 2 hours agofunction date_range($fdate,$fmonth,$tdate,$tmonth,$year) { $this->db->select('*'); $this->db->where('order_date >=',date('Y-m-d',mktime(0,0,0,$fmonth,$fdate,$year))); $this->db->where('order_date <=',date('Y-m-d',mktime(0,0,0,$tmonth,$tdate,$year))); return $this->db->get('orders'); }
– Uraj 2 hours ago