【问题标题】:Codeigniter highcharttable count how many data in a monthCodeigniter highcharttable 统计一个月有多少数据
【发布时间】:2018-04-03 11:31:10
【问题描述】:

我有这张project 表,你可以在下面看到,从下表中我想制作一个图表,其中包含该月有多少project

id | project_name | start_date |
1  | proj1        | 2017-09-01 | 
2  | proj2        | 2017-09-01 |
3  | proj3        | 2017-09-01 |
4  | proj4        | 2017-08-01 | 
5  | proj5        | 2017-08-01 |

到目前为止我所做的是制作一个模型,然后我很困惑下一步我应该做什么,因为我创建的模型不是动态的,它只读取某个月份,在这种情况下是 month=@ 987654327@

public function get_monthly_totals($theYear = '', $theMonth = '')
{
    $select = "
        SELECT COUNT(*) AS start_count
        FROM
           project
        WHERE 
           MONTH(start_date)=09";
    return $this->db->query($select);
}

我想制作一个像上面这样的图表,我使用的插件是 highcharttable 它将html表格数据转换为图表,我如何制作这样的东西,我如何制作一个月即使没有数据也存在,以及如何将数据连接到正确的月份?

【问题讨论】:

    标签: php mysql codeigniter charts highcharts


    【解决方案1】:

    我设法通过在我的控制器中做这样的事情来做到这一点,我知道这并不漂亮,但现在还可以

    public function dashboard_project()
    {   
        $thn = $this->input->post('tahun');
        $id = md5($this->session->userdata('id'));
        $data['rows'] = $this->pengguna_m->getPengguna($id)->row();
    
        $data['januari'] = $this->dashboard_m->get_kategori_totals('01',$thn)->num_rows();
        $data['februari'] = $this->dashboard_m->get_kategori_totals('02',$thn)->num_rows();
        $data['maret'] = $this->dashboard_m->get_kategori_totals('03',$thn)->num_rows();
        $data['april'] = $this->dashboard_m->get_kategori_totals('04',$thn)->num_rows();
        $data['mei'] = $this->dashboard_m->get_kategori_totals('05',$thn)->num_rows();
        $data['juni'] = $this->dashboard_m->get_kategori_totals('06',$thn)->num_rows();
        $data['juli'] = $this->dashboard_m->get_kategori_totals('07',$thn)->num_rows();
        $data['agustus'] = $this->dashboard_m->get_kategori_totals('08',$thn)->num_rows();
        $data['september'] = $this->dashboard_m->get_kategori_totals('09',$thn)->num_rows();
        $data['november'] = $this->dashboard_m->get_kategori_totals('10',$thn)->num_rows();
        $data['oktober'] = $this->dashboard_m->get_kategori_totals('11',$thn)->num_rows();
        $data['desember'] = $this->dashboard_m->get_kategori_totals('12',$thn)->num_rows();
    
        $data['title']= 'Aplikasi Saranabudi';
        $data['aktif']  = 'Jumlah Kategori Project';
        $data['judul_hal']= 'Dashboard Kategori Project';
    
        $this->load->view('layout/header',$data);
        $this->load->view('layout/sidebar',$data);
        $this->load->view('dashboard/pelanggan/home');
        $this->load->view('layout/footer');
    }
    

    【讨论】:

      【解决方案2】:

      这是我计算一年内每月的简单语法

      public function get_monthly_totals($theYear = ''){
          $select = "
              SELECT 
                COUNT(*) AS start_count,
                MONTH(start_date) as month
              FROM
                 project
              WHERE 
                 YEAR(start_date)='$theYear'
              GROUP BY
                 MONTH(start_date)
          ";
          return $this->db->query($select);
      }
      

      【讨论】:

        猜你喜欢
        • 2018-04-12
        • 1970-01-01
        • 2021-06-30
        • 1970-01-01
        • 1970-01-01
        • 2017-04-28
        • 2016-02-26
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多