codeigniter php 明智的搜索日期未显示所有结果

codeigniter php search date wise not showing all results

我有一个 codeigniter 网站,上面有简单的搜索框,如下所示:

<form method="post" action="<?php echo base_url()?>homecontroller/search">
  <label>Month: </label>

  <select class="form-select" id="basicSelect" name="month">
    <option value="01">January</option>
    <option value="02">February</option>
    <option value="03">March</option>
    <option value="04">April</option>
    <option value="05">May</option>
    <option value="06">June</option>
    <option value="07">July</option>
    <option value="08">August</option>
    <option value="09">September</option>
    <option value="10">October</option>
    <option value="11">November</option>
    <option value="12">December</option>


  </select>

  <label>Year: </label>

  <select class="form-select" id="basicSelect" name="year">
    <option value="2022">2022</option>
    <option value="2021">2021</option>
    <option value="2020">2020</option>
    <option value="2019">2019</option>
    <option value="2018">2018</option>
    <option value="2017">2017</option>
    <option value="2016">2016</option>
    <option value="2015">2015</option>
    <option value="2014">2014</option>
    <option value="2013">2013</option>
    <option value="2012">2012</option>


  </select>

  <input style="margin-top:24%" type="submit" class="btn btn-primary ml-1" name="billing" value="SEARCH">

</form>

我的控制器看起来像:

  $month=$this->input->post('month');
    $year=$this->input->post('year');

    $stotal=$year.'-'.$month;
   
    $data['search'] = $this->user->searchbilling($stotal);

我在模型中执行了以下代码来获取结果:

public function searchbilling($stotal) { 
$this->db->select('*, SUM(quantity) as quantity'); 
$this->db->from('delivered'); 
$this->db->like('date', $stotal); 
$this->db->group_by('YEAR(date), MONTH(date), customer'); 
$query = $this->db->get(); 
$result = $query->result(); 
return $result; }

但是这并不能显示那个月的所有结果,谁能告诉我这里有什么问题,在此先感谢

你可以这样试试where("DATE_FORMAT(date,'%Y-%m') =", $stotal)

public function searchbilling($stotal) { 
  $this->db->select('*, SUM(quantity) as quantity'); 
  $this->db->from('delivered'); 
  $this->db->where("DATE_FORMAT(date,'%Y-%m') =", $stotal); 
  $this->db->group_by('YEAR(date), MONTH(date), customer'); 
  $query = $this->db->get(); 
  $result = $query->result(); 
  return $result; 
}

你可以这样做 where("DATE_FORMAT(date,'FORMAT YOU NEED') =", $stotal)

public function searchbilling($stotal) { 
  $this->db->select('*, SUM(quantity) as quantity'); 
  $this->db->from('delivered'); 
  $this->db->where("DATE_FORMAT(date,'FORMAT YOU NEED') =", $stotal); 
  $this->db->group_by('YEAR(date), MONTH(date), customer'); 
  $query = $this->db->get(); 
  $result = $query->result(); 
  return $result; 
}