PHP json数据使用

在测试一个东西,为了实现FLOT,所以倒腾了下。

<?php

$connection = mysql_connect("localhost","root","mojige123");
$db = mysql_select_db("3d_database",$connection);

$query="select time,number from old_papar";
$result=mysql_query($query);
//create array of pairs of x and y values
$dataset1 = array();
while ($row = mysql_fetch_assoc($result)) { //or whatever
    $dataset1[] = array( $row['time'], $row['number'] );
}
?>

        $(function() {
                var data=<?php echo json_encode($dataset1); ?>

                $.plot("#placeholder", [ data ], {
                        series: {
                                bars: {
                                        show: true,
                                        barWidth: 0.6,
                                        align: "center"
                                }
                        },
                        xaxis: {
                                mode: "categories",
                                tickLength: 0
                        }
                });

                // Add the Flot version string to the footer

                $("#footer").prepend("Flot " + $.plot.version + " &ndash; ");
        });

        </script>
原文地址:https://www.cnblogs.com/xiaoCon/p/3244794.html