• 技术文章 >数据库 >mysql教程

    从数据库中取出最近三十天的数据并生成柱状图

    2016-06-07 18:03:32原创524

    从数据库中取出最近三十天的数据并生成柱状图的代码,需要的朋友可以参考下。

    在终端用cd 命令进入文件目录
    说明:此处例子我是拿项目中的一个例子讲解的。
    1、新建一个项目 :用终端输入:zf create project Airline 格式:zf create action project project-name 备注:这些格式可以在终端输入zf 查看
    2、新建一个action :zf create action dirgramshow index 格式:zf create action action-name controller-name
    3、新建一个 model :zf create db-table flightinformation
    action 层代码:indexController.php
    代码如下:
    public function indexAction ()
    {
    // action body
    $db = new Application_Model_DbTable_Flightinformation();
    /*获取最近30天内的数目
    * select day(boo_time) as day,count(boo_autoid)as count,boo_time from bookinformation
    where flag_pass=0 and date_sub(now(), interval 30 day)<=date(boo_time)
    group by DATE_FORMAT(boo_time,'%m %d')
    */
    $sql = "select DATE_FORMAT(boo_time,'%m-%d') as day,count(boo_autoid)as count from bookinformation " .
    "where flag_pass=0 and date_sub(now(), interval 30 day)<=date(boo_time) " .
    "group by DATE_FORMAT(boo_time,'%m %d')";
    $result = $db->getAllInfo($sql)->fetchAll();
    $this->view->result=$result;
    }

    view 层代码:dirgramshow.phtml
    代码如下:




    航班折线图




    Loading graph...





    model 层代码:Flightinformation.php
    代码如下:
    class Application_Model_DbTable_Flightinformation extends Zend_Db_Table_Abstract
    {
    protected $_name = 'flightinformation';
    public function getAllInfo($sql){
    $adapter = Zend_Registry::get('db');
    $flightinformation = $adapter->query($sql);
    return $flightinformation;
    }
    }

    最后的效果图如下:

    声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。
    专题推荐:柱状图
    上一篇:MySQL中字符串函数详细介绍 下一篇:mysql cmd常用命令
    20期PHP线上班

    相关文章推荐

    • 【活动】充值PHP中文网VIP即送云服务器• MySQL约束与多表查询基础详解• MySQL学习之一条SQL是如何执行的?聊聊执行流程• 完全掌握MySQL主从延迟的解决方法• mysql hint是什么• 什么是mysql主从复制
    1/1

    PHP中文网