如何使用CodeIgniter解决日期范围搜索

时间:2018-06-11 03:41:34

标签: php mysql apache codeigniter xampp

控制器代码

public function getcari(){

    $tglawal=date('Y-m-d', strtotime($this->input->post('tgl1', TRUE)));
    $tglakhir=date('Y-m-d', strtotime($this->input->post('tgl2', TRUE)));
    $data['detail']=$this->traffic_model->cari($tglawal,$tglakhir); 
    $this->load->view('daftar_traffic', $data); //menampilkan data yang sudah dicari
}

型号代码

function cari($tglawal,$tglakhir){      

$this->db->select('DATE_FORMAT(tgl, %d %M %Y) AS tanggal,COUNT(IF(kategori.parent=35 , VALUE, NULL)) AS Software,  COUNT(IF(kategori.parent=33 , VALUE, NULL)) AS Indent,  COUNT(IF(kategori.parent=32 , VALUE, NULL)) AS Ready, COUNT((DATE_FORMAT(tgl, %d - %m - %Y))) AS Total'); //changed the code here from COUNT(clients.id) AS num_rows
$this->db->from('masalah ');
$this->db->where('DATE(masalah.tgl) >=', $tglawal);
$this->db->where('DATE(masalah.tgl) <=', $tglakhir);
$this->db->join('kategori, kategori.kategori=masalah.kategori', 'left');
$this->db->group_by('tanggal');
$query = $this->db->get();
return $query->result();
}

查看代码

<form action="<?php echo site_url('traffic/getcari');?>" method="post"><input type="date" name="tgl1" palceholder="Input date" requaried="true" /> <input type="date" name="tgl2" palceholder="Input date" requaried="true" /><button type="submit">Cari</button> <a href="<?php echo site_url('traffic'); ?>" style="text-decoration:none; color: black;">Reset</a>

  

错误...警告:   包括(C:\ XAMPP \ htdocs中\ portalacw \应用\视图\错误\ HTML \ error_php.php):   无法打开流:没有这样的文件或目录   第269行的C:\ xampp \ htdocs \ portalacw \ system \ core \ Exceptions.php

     

警告:include():打开失败   'C:\ XAMPP \ htdocs中\ portalacw \程序\意见\错误\ HTML \ error_php.php'   包含(include_path ='C:\ xampp \ php \ PEAR')in   第269行的C:\ xampp \ htdocs \ portalacw \ system \ core \ Exceptions.php

     

致命错误:在null中调用成员函数cari()   C:\ XAMPP \ htdocs中\ portalacw \应用\模块\交通\控制器\ traffic.php   第24行

     

警告:   包括(C:\ XAMPP \ htdocs中\ portalacw \应用\视图\错误\ HTML \ error_php.php):   无法打开流:没有这样的文件或目录   第269行的C:\ xampp \ htdocs \ portalacw \ system \ core \ Exceptions.php

     

警告:include():打开失败   'C:\ XAMPP \ htdocs中\ portalacw \程序\意见\错误\ HTML \ error_php.php'   包含(include_path ='C:\ xampp \ php \ PEAR')in   第269行的C:\ xampp \ htdocs \ portalacw \ system \ core \ Exceptions.php

     

警告:   包括(C:\ XAMPP \ htdocs中\ portalacw \应用\视图\错误\ HTML \ error_php.php):   无法打开流:没有这样的文件或目录   第269行的C:\ xampp \ htdocs \ portalacw \ system \ core \ Exceptions.php

     

警告:include():打开失败   'C:\ XAMPP \ htdocs中\ portalacw \程序\意见\错误\ HTML \ error_php.php'   包含(include_path ='C:\ xampp \ php \ PEAR')in   第269行的C:\ xampp \ htdocs \ portalacw \ system \ core \ Exceptions.php'

请求帮助我

1 个答案:

答案 0 :(得分:-2)

在我看来,您的问题是因为您没有正确加载模型。 因此,您的控制器将null设为Month, Group, Hits 2017-12-01,X,123 2018-01-01,X,214 2017-02-01,X,150 2017-03-01,X,40 2017-04-01,X,65 2017-12-01,Y,117 2018-01-01,Y,200 2017-02-01,Y,191 2017-03-01,Y,151 2017-04-01,Y,48