如何过滤月份和年份的数据,但始终显示30个数据(例如)

时间:2018-12-13 09:49:16

标签: codeigniter

我有一个表,我创建了一个过滤器月份和年份,并得到过滤器的结果“状态”列,例如,在过滤我显示的数据之前,例如有20个。过滤数据之后,我显示的数据仍然是20,但只有“状态”已更改

 function status_data($year,$month){

    $this->db->where('YEAR(waktu_upload)', $year); 
    $this->db->where('MONTH(waktu_upload)', $month); 
    $this->db->select('*');
    $this->db->from('puskesmas');
    $this->db->select("puskesmas.id_puskesmas");
    $this->db->group_by('puskesmas.nama_puskesmas');
    $this->db->join('penyakit', 'puskesmas.id_puskesmas=penyakit.id_puskesmas', 'left');




    $data= $this->db->get()->result();

    foreach ($data as $value) {

         $query = $this->db->query("SELECT * FROM penyakit WHERE MONTH(waktu_upload) = '$month' AND YEAR(waktu_upload) = '$year'");  


         // $query = $this->db->query("SELECT * FROM penyakit WHERE MONTH(waktu_upload) = MONTH(CURRENT_DATE) AND id_puskesmas=".$value->id_puskesmas);

        $num = $query->num_rows();

         $value->num = $num;
        if($num = 0 ){
            $value->status = "<button type='button' class='btn btn-danger btn-rounded'> Uncomplete</button>";
        }elseif($num < 19){
            $value->status = "<button type='button' class='btn btn-danger btn-rounded'> Uncomplete</button>";
        }elseif($num >= 20){
            $value->status = "<button type='button' class='btn btn-success btn-rounded'>Complete</button>";
        }
    }
    //die(print_r($data));
    return $data;
}

是我的模特。和我的控制器

public function view_status(){
    $year = $this->input->post('tahun');
    $month = $this->input->post('bulan');

    $this->data['hasil']=$this->app_model->status_data($year,$month);

    $this->load->view('view_status',$this->data);

}

我有这样的看法

 <div class="bulan" align="center">
                <label>Bulan</label><br>
                  <select name="bulan">
                      <!-- <option value="">Pilih</option> -->
                      <option value="01">Januari</option>
                      <option value="02">Februari</option>
                      <option value="03">Maret</option>
                      <option value="04">April</option>
                      <option value="05">Mei</option>
                      <option value="06">Juni</option>
                      <option value="07">Juli</option>
                      <option value="08">Agustus</option>
                      <option value="09">September</option>
                      <option value="10">Oktober</option>
                      <option value="11">November</option>
                      <option value="12">Desember</option>
                  </select>
                </div>
                <div class="tahun" align="center">
                <?php
                $now=date('Y');
                echo "<select name=tahun>";
                for ($a=2010;$a<=$now;$a++)
                {
                     echo "<option value='$a'>$a</option>";
                }
                echo "</select>";
                ?>
                <br><br>
                <input type="submit" name="submit">
                </div>
              </form>
                    </h5>
                    <table class="table table-bordered table-responsive-lg" >

                          <thead>
                            <tr>
                              <th>Nama Puskesmas</th>
                              <th>Nama Petugas</th>
                              <th>Status</th>
                              <th>Lihat Data</th>
                            </tr>
                            </thead>
                            <?php


                            foreach($hasil as $u){
                             ?>

                            <tr>
                              <td><?php echo $u->nama_puskesmas?></td>
                              <td><?php echo $u->nama_petugas?></td>
                              <td><?php echo $u->status?></td>
                              <td> <button class="btn btn-info btn-sm">Lihat Data</button></td>


                            </tr>
                            <?php } ?>
                    </table>

在我的查询中,它仅显示2个数据,即使显示错误的“状态”。

nb如果我使用current_date(当前时间)过滤数据,那么结果将显示20个数据,这就是我想要的

喜欢这个img image

我该如何解决?

0 个答案:

没有答案