我有这个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
= 09
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表数据转换为图表,我是如何制作类似的东西,我如何制作一个月的即使没有数据,也存在如何将数据连接到正确的月份?
答案 0 :(得分:0)
我设法通过在我的控制器中做这样的事情来做到这一点,我知道这不是很漂亮,但现在还可以。
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');
}
答案 1 :(得分:0)
这是我一年内每月计算的简单语法
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);
}