0
cust period score
x 012017 98.04
x 122016 99.11
x 112016 95.84
y 012017 85.00
y 022017 100.00
y 012017 90.00
您好,我想在php的表格resut中以javascript形式回显, 我该怎么做?用我的代码我不能在行之间设置逗号 的结果是;数据:[[012017,90.00],[] - >>最后一个方括号拆除代码。将mysql数据转换为使用php的javascript图表
<script>
$(function() {
/**
* For each cust in table
*/
var flotChartData = [
{
label: "bar",
data: [ [period , score]]
}
];
/**
* Bar Chart Options for Analytics
*/
var flotBarOptions = {
series: {
bars: {
show: true,
barWidth: 0.8,
fill: true,
fillColor: {
colors: [ { opacity: 1 }, { opacity: 1 } ]
},
lineWidth: 1
}
},
xaxis: {
tickDecimals: 0
},
colors: ["#62cb31"],
grid: {
show: true
},
legend: {
show: false
}
};
$.plot($("#flot-bar-chartCUST"), flotChartData, flotBarOptions);
});
</script>
这是我的代码不起作用。
<?php
$result = mysqli_query($con,"SELECT * FROM main order by cust asc , period asc");
$pdocno=0;
$x=1;
while($row = mysqli_fetch_array($result)) {
$docno= $row["cust"] ;
if($x==1 or $docno!==$pdocno){
if($x!==1 and $docno!==$pdocno){
echo "]
}
];
/**
* Bar Chart Options for Analytics
*/
var flotBarOptions = {
series: {
bars: {
show: true,
barWidth: 0.8,
fill: true,
fillColor: {
colors: [ { opacity: 1 }, { opacity: 1 } ]
},
lineWidth: 1
}
},
xaxis: {
tickDecimals: 0
},
colors: ['#62cb31'],
grid: {
show: true
},
legend: {
show: false
}
};
$.plot($('#flot-bar-chart$img'), flotChartData, flotBarOptions);";
}
echo " $docno";
$img = $row["cust"] ;
echo "var flotChartData = [
{
label: 'bar',
data: [ [";
}
$step= $row["period"] ;
$score= $row["score"] ;
echo $step.",";
echo $score;
if($docno!==$pdocno){
echo "],[";
}
$pdocno=$docno;
++$x;
}
echo "]
}
];
/**
* Bar Chart Options for Analytics
*/
var flotBarOptions = {
series: {
bars: {
show: true,
barWidth: 0.8,
fill: true,
fillColor: {
colors: [ { opacity: 1 }, { opacity: 1 } ]
},
lineWidth: 1
}
},
xaxis: {
tickDecimals: 0
},
colors: ['#62cb31'],
grid: {
show: true
},
legend: {
show: false
}
};
$.plot($('#flot-bar-chart$img'), flotChartData, flotBarOptions);";;
?>
数据来自空:数据:[]},并正在创建一次,图表数据。它必须为表中的所有客户创建。 –
打印查询结果。确保它不是空的。 –