0

我使用 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);
}
4

1 回答 1

1

这是真的吗?你已经知道答案了!

SELECT * FROM result ORDER BY id DESC LIMIT 1

将其更改为

SELECT * FROM result ORDER BY id DESC LIMIT 3

???

于 2013-07-30T11:56:15.203 回答