如何从控制器获取数据查看(高级)php codeigniter

时间:2015-03-18 07:22:53

标签: php sql codeigniter

我想看看Highchart系列的价值,但是当我调试它时却没有显示值。 这是我的代码

这是我的观点

<script type="text/javascript" src="<?php echo base_url(); ?>public/jquery-1.11.2.min.js"></script>
<script type="text/javascript" src="<?php echo base_url(); ?>public/highcharts/js/highcharts.js"></script>
<script type="text/javascript" src="<?php echo base_url(); ?>public/highcharts/js/highcharts-3d.js"></script>
<script type="text/javascript" src="<?php echo base_url(); ?>public/highcharts/js/modules/exporting.js"></script>
<script type="text/javascript" src="<?php echo base_url(); ?>public/highcharts/js/themes/grid-light.js"></script>

<style type="text/css">
</style>        


<script type="text/javascript">
    var chart1;
    jQuery(document).ready(function(){
        chart1 = new Highcharts.Chart({
            chart: {
                renderTo: 'container',
                type: 'column',
                borderWidth: 2,
                animation: {
                    duration: 1000
                },
                spacingRight: 25,
                backgroundColor: {
            linearGradient: [0, 0, 500, 500],
            stops: [
                [0, 'rgb(255, 255, 255)'],
                [1, 'rgb(229, 238, 238)']
            ]
        },
            },
            tooltip: {
                backgroundColor: '#FCFFC5',
                shadow: true,
            },

            title: {
                text: 'Store Chart'
            },
            credits: {
                enabled: false
            },
            xAxis: {
                categories: [<?php echo "'".implode("','",$branch_name)."'";?>]
            },
            yAxis: {
                title: {
                    text: 'Tingkat Penjualan'
                }
            },


            exporting: {
                buttons: {
                contextButton: {
                text: 'Export'
                    }
                }
            },
            series: [<?php echo "'".implode("','",$branch_sell)."'";?>],
                 plotOptions: {
            series: {
            color: '#66B2FF'
            }
        }


        });

        });
        </script>

这是控制器

public function index()
{

    $data = array();
    $this->menu_handler->set_header($data,1,0);
    $this->load->model('m_admin');
    $get_branch         = $this->m_admin->get_chart_store();

    $get_selling_store  = $this->m_admin->get_sell_store();


    $data['branch_name'] = array();

    $data['branch_sell'] = array();

    for($i=0,$n=count($get_branch); $i<$n; $i++)
    {
        $data['branch_name'][] = $get_branch[$i]->NAMA_CABANG;
    }

    for($i=0,$n=count($get_selling_store); $i<$n; $i++)
    {
        $data['branch_sell'][]  = $get_selling_store[$i]->rslt;
    }
    $series_data[]  = array('name' => 'Branch Store', 'data' => array($get_selling_store));



    $data['series_data'] = json_encode($series_data);


    $this->load->view('welcome_message', $data);
    global $file_counter,$error_file,$size_counter; 

}

这是我的模特

<?php if (!defined('BASEPATH'))
exit('No direct script access allowed');
function get_chart_store($id_store=''){
    global $sec_database;
    if(empty($id_store))
    {
        $get_detail = $sec_database->select('*')->get('MST_CABANG')->result();
    }
    else
    {
        $get_detail = $sec_database->select('*')->where('CABANG_ID',$id_store)->get('MST_CABANG')->result();
    }

    if(count($get_detail) > 0)
    {
        return $get_detail;
    }
    else
    {
        return 1;   
    }
}

function get_sell_store($id_sell='')
{
    global $sec_database;
    $q_detailstore = "
        SELECT
        sd.CABANG_ID,
        sd.`NAMA_CABANG`,
        SUM(SALES_TOTAL) as rslt

        FROM
        MST_SALES as md
        RIGHT JOIN MST_CABANG as sd
        ON md.`CABANG_ID` = sd.CABANG_ID

        GROUP BY
        sd.CABANG_ID 
    ";
    $get_detail_selling = $sec_database->query($q_detailstore,array($id_sell))->result();
    if(count($get_detail_selling) > 0)
    {
        return $get_detail_selling;
    } 
    else
    {
        return 1;
    }

}

图表只显示系列,但是 我怎样才能在图表中获得系列的价值?抱歉,我是新手.. thx之前

1 个答案:

答案 0 :(得分:0)

implode()无法使用多维数组。所以它没有打印价值

尝试

$data['branch_name'] = $get_branch[$i]->NAMA_CABANG;

而不是

$data['branch_name'][] = $get_branch[$i]->NAMA_CABANG;

在您的控制器中。与 branch_sell 变量

相同

<强>更新

for($i=0,$n=count($get_branch); $i<$n; $i++)
{
    $data['branch_name'] = $get_branch[$i]->NAMA_CABANG;
}

array_walk($data['branch_name'],function (&$val){ $val="'".$val."'";});