使用PHP Codeigniter

时间:2018-02-15 06:13:52

标签: php date datepicker codeigniter-3

我是Code-Igniter的新手。我试图在两个日期过滤数据(尝试在两个日期之间查找数据)。我还有四个带有日期范围过滤功能的过滤器。要获取数据,我已使用Stored procedures。如果我在PHPMyAdmin中执行它,我的过程工作正常。如果我使用其他四个过滤器过滤数据,它会为我提供正确的输出,但如果我应用日期过滤器,它会给我"找不到记录" ,记录存在于数据库中。

以下是我的模型代码:

public function getDefectyByAreaCluster($timeframe, $area, $cluster, $statusId, $startdate, $enddate)
    {
        $query = $this->db->query("call fetch_defect_area_cluster_timeframe ($timeframe,$area,$cluster,$statusId,$startdate,$enddate)");

        if ($query) {
            $data = $query->result();
            $query->next_result(); 
            $query->free_result();
            return $data;
        }else{
            return false;
        }
    }

以下是我的控制器代码:

public function DefectList()
    {   
        $user = $this->ion_auth->user()->row();
        $data['username'] = $user->username;

        $data['user_id'] = $user->id;
        $user_id = $user->id;
        $data['groupId'] = $this->l->groupId($user_id);
        $data['group'] = $data['groupId']['0']->group_id;

        $timeframe=$this->input->post('defect_time_frame');
        $area=$this->input->post('area_id');
        $cluster=$this->input->post('cluster_id');
        $statusId=$this->input->post('defect_status');
        $startdate=$this->input->post('defect_followup_date');
        $enddate=$this->input->post('defect_followup_date');

        // $startdate=DATE_FORMAT($this->input->post(strtotime('defect_followup_date')), '%m/%d/%Y');
        // $enddate=DATE_FORMAT($this->input->post(strtotime('defect_followup_date')), '%m/%d/%Y');

        if($timeframe == ''){
            $timeframe =0;
        }       
        if($area == ''){
            $area =0;
        }
        if($cluster == ''){
            $cluster =0;
        }  
        if($statusId == ''){
            $statusId =0;
        }   
        if($startdate == ''){
            $startdate =0;
        }
        if($enddate == ''){
            $enddate =0;
        }

        $data['areas'] = $this->p->area();
        $data['clusters'] = $this->p->cluster();

        //$data['defectslist'] = $this->p->defectList();
        $data['defectStatus'] =$this->p->selectDefectStatus();
        $data['defecttimeframe'] =$this->p->selectDefectTimeframe();
        $data['defectslist'] = $this->p->getDefectyByAreaCluster($timeframe, $area, $cluster, $statusId, $startdate, $enddate);
        // echo "<pre>";
        // print_r($data['defectslist']);
        // echo "</pre>";
        // exit();
        $data['title'] = 'Property Defects List';

        $this->load->view('template/header', $data); 
        $this->load->view('Property/defect_list', $data); 
        $this->load->view('template/footer'); 
    }

以下是我的观看代码:

<div class="form-group">&nbsp;&nbsp;</div>
            <label>FUP Start Date:</label>
            <div class="input-group date">
            <!-- <div class="input-group-addon">
            <i class="fa fa-calendar"></i>
            </div> -->
            <input type="text" name="defect_followup_date" class="form-control pull-right" id="datepicker3" />
            </div>
        </div>
    <div class="form-group">
    <div class="form-group">&nbsp;&nbsp;</div>
            <label>FUP End Date:</label>
            <div class="input-group date">
            <!-- <div class="input-group-addon">
            <i class="fa fa-calendar"></i>
            </div> -->
            <input type="text" name="defect_followup_date" class="form-control pull-right" id="datepicker4" />
            </div>
        </div>

注意:我将defect_followup_dateVARCHAR格式存储在数据库中。

我使用datepicker来选择日期,我如何转换该datepicker值(&#39; mm / dd / yyyy&#39;)以匹配VARCHAR值(&#39; mm / dd / yyyy& #39;)格式?

欢迎任何形式的帮助。提前谢谢。

0 个答案:

没有答案