PHP和MySQL与Morris图表

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

我正在使用morris图表,但不知道如何打印两种类型哦PHP和MySQL的结果 p>

我有这个代码似乎很好地显示了图表中的访问次数,但希望包括一天内访问但不知道该怎么做的不同用户的数量。 p>

  $ query =“
SELECT DATE(date)AS dt,COUNT(*)AS cnt FROM`acessos` GROUP BY DATE(date)
”; 
 $ result = mysql_query(  $ query,$ fb)或die(mysql_error()); 
 $ num_rows = mysql_num_rows($ result); 
  code>  pre> 
 
 

$(function(){ p>

  Morris.Area({
 element:'morris-area-chart',
 data:[
&lt;?php while($ row = mysql_fetch_array($ result)  ){?&gt; 
 {
 period:'&lt;?php echo $ row ['dt'];?&gt;',
 acessos:'&lt;?php echo $ row ['cnt'] ;?  &gt;',
 user:'&lt;?php echo $ row ['user'];?&gt;',
},
&lt;?php}?&gt;],
 xkey:'period'  ,
 ykeys:['acessos','user'],
标签:['acessos','用户 '],
 x标签:['day'],
 pointSize:2,
 hideHover:'auto',
 resize:true 
}); 
  code>  pre> 
 \  n 

}); p>

任何人都有想法? 欣赏帮助 p> div>

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.