我是 PHP/CodeIgniter 的新手,正在制作一個表格,用于在特定時間范圍內從 Mysql 中檢索值的計數。
控制器類:
public function totallistings($slug='')
{
$this->load->library('pagination');
$main['page_title']=$this->config->item('site_name').' - Listings Reports';
$main['header']=$this->adminheader();
$main['footer']=$this->adminfooter();
$main['left']=$this->adminleftmenu();
$content='';
$fdate = $this->input->post("fdate");
$content['tdate'] = $tdate = $this->input->post("tdate");
if(isset($fdate)){
$content['fdate'] =$fdate;
}else{
$content['fdate'] = '';
}
if(isset($tdate)){
$content['tdate'] =$tdate;
}else{
$content['tdate'] ='';
}
$main['content']=$this->load->view('crm/reports/totallistings',$content,true);
$main['jsArray'] = array('public/assets/plugins/datatables/jquery.dataTables.min.js' );
$main['cssArray'] = array('public/assets/plugins/datatables/jquery.dataTables.min.css','public/assets/css/reports.css');
$this->load->view('crm/main',$main);
$content['groupedleads'] = $this->leads_model->get_listingstatus($fdate,$tdate);
}
但這給了我在我的網頁上為 foreach() 錯誤提供的無效引數:

基本上我想把它作為這樣的東西,你只需要傳遞開始日期和結束日期,它就會回傳一個包含每個 status_to 值計數的表:

uj5u.com熱心網友回復:
您需要在加載視圖之前將資料設定到陣列中,否則視圖groupedleads中將不存在該值。
在您的totallistings()-method 中,移動最后一行:
$content['groupedleads'] = $this->leads_model->get_listingstatus($fdate,$tdate);
并在加載視圖之前放置它:
$content['groupedleads'] = $this->leads_model->get_listingstatus($fdate,$tdate);
$main['content'] = $this->load->view('crm/reports/totallistings',$content,true);
...
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/315047.html
