我从查询中选择的行是
## Selected rows from query ##
id rank Date
2 5 2016-03-15
4 3 2016-04-15
5 2 2016-04-15
我的查询是
$ touserid ='26'; $ teamcode =“ RXqYLM”;
查询=从* ssign_emotions中选择*,SUM(rank_emotions)作为总数,其中to_user_id ='$ touserid'和teamcode ='$ teamcode';
所以,我得到了完美的总数,但问题是我想在图表中显示几个月,所以我做了几个月。
$date = $row['date'];
$time = strtotime($date);
$month = date("F",$time);
所以从这个代码我现在有了一个月,问题是我必须将两者结合起来,我想要按月排列用户等级并在Graph中显示。
我尝试了下面的代码,但我想按月排序,这意味着如果一个月内如果用户具有多个级别,则这些值必须是求和值,因此在数据字段的4月月份示例中,级别为8。
<?php
include("header.php");
include("config.php");
$touserid = '26';
$teamcode = "RXqYLM";
$name = $_POST['teammembername'];
if(isset($_POST['teammembername']))
{
$touserid = '26';
$teamcode = "RXqYLM";
$name = $_POST['teammembername'];
$res = $conn -> query("select *,SUM(rank_emotions) as total, MONTH(date) as month from assign_emotions where to_user_id='$touserid' and teamcode='$teamcode' GROUP BY MONTH(date)");
$counter = 0;
while($row = mysqli_fetch_assoc($res))
{
echo $row['month'];
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/highcharts-more.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
</head>
<body>
<script>
$(function () {
$('#container').highcharts({
chart: {
type: 'spline'
},
title: {
text: 'KPI Chart Monthwise'
},
xAxis: {
categories: ['Jan', 'Feb', 'March', 'April', 'May','June', 'July', 'August', 'September', 'October', 'Nov', 'December']
},
credits: {
enabled: false
},
series: [{
name: '<?php echo "bhavin"; ?>',
data: [<?php if($row['month'] == '1')
{
echo $row['total'];
}
else
{
echo '0';
} ?>, 3, 4, 7, 2, 0, 0, 0, 0, -2, 0 ,0]
}]
});
});
</script>
<div id="container" style="height: 400px; margin: auto; min-width: 310px; max-width: 600px"></div>
</body>
</html>
如果对这个问题有任何疑问,请告诉我。
如果您更改查询以按月将结果分组
$res = $conn -> query("
select *,SUM(rank_emotions) as total, MONTH(date) as month
from assign_emotions
where to_user_id='$touserid'
and teamcode='$teamcode'
GROUP BY MONTH(date)");
这将为您提供每个月的总数
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句