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);";;
?>
數據來自空:數據:[]},並正在創建一次,圖表數據。它必須爲表中的所有客戶創建。 –
打印查詢結果。確保它不是空的。 –