Chat.js,Codeigniter和MySQL。恢复数据有问题

时间:2016-06-30 04:33:28

标签: codeigniter chart.js

所以,我想从mysql中提取数据,并按月组织。我将日期与月份分开并应用SUM,以及所有月份的值,并组织 chart.js 我的问题是在图表上。图表显示了独特月份的所有结果。 1月有这么多的数据,所有这些数据都将在2月,例如...

我的控制器:

`<?php
 defined('BASEPATH') OR exit('No direct script access allowed');

 class start extends CI_Controller {

public function index(){
$this->load->model('Start_class');
$data['janeiro']    = $this->Start_class->janeiro();
$data['fevereiro']  = $this->Start_class->fevereiro();`

我的模特:

function janeiro(){
$minvalue = '2016-01-01';
$maxvalue = '2016-01-31';

$query1   = $this->db->select('SUM(valorcompra) as valorcompra')->from('compravista')->where("datavencimento BETWEEN '$minvalue' AND '$maxvalue' ")->get();
$retorno = $query1->row()->valorcompra;
return $retorno;
}

function fevereiro(){
$minvalue = '2016-02-01';
$maxvalue = '2016-02-31';

$query2   = $this->db->select('SUM(valorcompra) as valorcompra')->from('compravista')->where("datavencimento BETWEEN '$minvalue' AND '$maxvalue'")->get();
$retorno = $query2->row()->valorcompra;
return $retorno;
}

和我的图表:

var data = {
    labels: ["Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro"],
    datasets: [
    {
        label: "Dados primários",
        fillColor: "rgba(151,187,205,0.5)",
        strokeColor: "rgba(151,187,205,0.8)",
        highlightFill: "rgba(151,187,205,0.75)",
        highlightStroke: "rgba(151,187,205,1)",

        data: [<? echo $janeiro ?>, <? echo $fevereiro ?>, randomnb(), randomnb(), randomnb(), randomnb(), randomnb(), randomnb(), randomnb(), randomnb(), randomnb(), randomnb()]
    },

1 个答案:

答案 0 :(得分:0)

在模型中,您使用了Where语句错误。

替换

where("datavencimento BETWEEN '$minvalue' AND '$maxvalue' ")

where("datavencimento BETWEEN '$minvalue' AND '$maxvalue' ",null,false)

在两个查询中。