duanfu1942 2014-03-14 11:31 采纳率: 100%
浏览 67
已采纳

PHP和MySQL与Morris图表

I'm working with morris chart but do not know how to print two types oh Results with PHP and MySQL

I have this code that seems to work well showing the number of visits in graph but wanted to include the number of different users accessing in a day but do not know how to do.

$query = "
SELECT DATE(date) AS dt, COUNT(*) AS cnt FROM `acessos` GROUP BY DATE(date)
";
$result = mysql_query($query, $fb) or die(mysql_error());
$num_rows = mysql_num_rows($result);

$(function() {

Morris.Area({
    element: 'morris-area-chart',
    data: [
    <?php while($row = mysql_fetch_array($result)){ ?>
    {
        period: '<?php echo $row['dt']; ?>',
        acessos: '<?php echo $row['cnt']; ?>',
        user: '<?php echo $row['user']; ?>',
    },
    <?php } ?>],
    xkey: 'period',
    ykeys: ['acessos','user'],
    labels: ['acessos','user'],
    xLabels:['day'],
    pointSize: 2,
    hideHover: 'auto',
    resize: true
});

});

Anyone have an idea? appreciate the help

  • 写回答

1条回答 默认 最新

  • dpcnm2132 2014-03-14 11:34
    关注

    This is addressing the number of different users. You should update your code to use something other than the "mysql_" functions.

    The function that you want is count(distinct). Assuming you have a UserId field, the query would look like:

    SELECT DATE(date) AS dt, COUNT(*) AS cnt, COUNT(DISTINCT UserId) as NumUsers
    FROM `acessos`
    GROUP BY DATE(date)
    ORDER BY DATE(date);
    

    Note that I also included an explicit order by. MySQL has deprecated the functionality that group by also does ordering.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 自适应 LMS 算法实现 FIR 最佳维纳滤波器matlab方案
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥15 Python3.5 相关代码写作
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像