我使用 Google graph 在 sql 表中绘制带有变量的图,下面是我的代码,如您所见,它用表的最后一行绘制了一个图,如何绘制最后一行 3?我知道我应该使用DESC LIMIT 3
但如何使用?
<?php
$result = mysql_query("SELECT * FROM result ORDER BY id DESC LIMIT 1");
$value=array();
while($r = mysql_fetch_assoc($result)) {
$year=$r['year'];
$sales=$r['sales'];
$expenses=$r['expenses'];
$val="[".$year.",".$sales.",".$expenses."]";
array_push($value,$val );
}
$final_value = implode(",", $value);
?>
function drawChart() {
var data = google.visualization.arrayToDataTable([
<?php echo $final_value?>
]);
var options = {
title: 'Company Performance'
};
var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
chart.draw(data, options);
}