Codeigniter highcharttable 统计一个月有多少数据
Posted
技术标签:
【中文标题】Codeigniter highcharttable 统计一个月有多少数据【英文标题】:Codeigniter highcharttable count how many data in a month 【发布时间】: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表格数据转换为图表,我如何制作这样的东西,我如何制作一个月即使没有数据也存在,以及如何将数据连接到正确的月份?
【问题讨论】:
【参考方案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);
【讨论】:
以上是关于Codeigniter highcharttable 统计一个月有多少数据的主要内容,如果未能解决你的问题,请参考以下文章
调用未定义函数 codeigniter\locale_set_default() 时出现 codeigniter 错误
codeigniter 中是不是有子查询库?或者我如何在codeigniter 3中进行子查询?
php优秀框架codeigniter学习系列——CodeIgniter.php概览
Codeigniter- Ajax Codeigniter Ajax - 通过ajax返回不止一行
CodeIgniter 4 项目中未定义的常量“CodeIgniter\Database\MySQLi\MYSQLI_STORE_RESULT”