我已经在我的网站上安装了 Highcharts,但我遇到了问题。MySQL 返回该值中的数据:
['26.03.2013', 1], ['26.03.2013', 1], ['26.03.2013', 1], ['26.03.2013', 1], ['26.03.2013', 1], ['11.03.2013', 1], ['21.03.2013', 1], ['22.03.2013', 1]
它包含在 Highcharts 中,如下所示:
$('#chart').highcharts({
chart: {
type: 'line'
},
title: {
text: 'Statistika prenosov'
},
xAxis: {
title: {
text:'Datum'
}
},
yAxis:{
title: {
text:'Prenosi'
},
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
},
series: [{
name: 'Prenosi',
data: [['26.03.2013', 1], ['26.03.2013', 1], ['26.03.2013', 1], ['26.03.2013', 1], ['26.03.2013', 1], ['11.03.2013', 1], ['21.03.2013', 1], ['22.03.2013', 1]]
}]
});
});
但我想,如果有 26.3.2013 三个日期,那么不要单独显示它们,而是将它们放在一起,所以结果应该是 3,而不是 3x1。
下面是我如何使用 PHP 获取结果:
$query=mysql_query("SELECT * FROM downloads WHERE prjID='".$_GET['id']."' ORDER BY date ASC");
$num=mysql_num_rows($query);
$res='';
$i=0;
while($row=mysql_fetch_array($query)){
$i++;
$date=date("d.m.Y", strtotime($row['date']));
$numb=1;
if($i!=$num){
$res.="['".$date."', ".$numb."], ";
}
else{
$res.="['".$date."', ".$numb."]";
}
}