谷歌图表php“表没有列”

时间:2013-07-03 20:39:31

标签: php web-applications google-visualization

我正在制作一个网络应用程序的图表。由于这是我的第一个webapp,我找了一个快速的totorial,我找到了这个:http://mireille.it/example-code-realtime-google-chart-with-mysql-json-ajax/

我将localhost更改为: jdbc:mysql:// localhost:3306 / threadcountstorage,并提供了我的用户名和密码。我已经按照教程(复制并粘贴和编辑代码)编译了我的webapp。

当我加载页面时,我看到的是“表没有列”标志,就是这样。 :(

Bellow是我的databaseQuery.php代码和google图表代码

PHP

<?php 
$con = mysql_connect('locahost', 'root', password) or die('Error connecting to server');
$query = mysql_query('SELECT * FROM threadcount');
$table = array();
$table['cols'] = array(
array('label' => 'id', 'type' => 'number'),
array('label' => 'threads', 'type' => 'number')
);
$rows = array();
while($r = mysql_fetch_assoc($query)) {
$temp = array();
$temp[] = array('v' => (int) $r['id']);
$temp[] = array('v' => (int) $r['threads']);
$rows[] = array('c' => $temp);
}
$table['rows'] = $rows;
$jsonTable = json_encode($table);
echo $jsonTable;
?>

谷歌图表脚本

    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
    <script type="text/javascript">

    google.load('visualization', '1.0', {'packages':['corechart']});

     google.setOnLoadCallback(drawChart);

    function drawChart() {

        var json = $.ajax({
                url: 'C:\grails\threadsAPP\grails-app\views\threadcount\databaseQuery.php',
                dataType: 'json',
                async: false
            }).responseText;

        var data = new google.visualization.DataTable(json);
        var options = {'title':'Total Thread Count',
                        'width':800,
                        'height':600};

        // Instantiate and draw our chart, passing in some options.
        var chart = new google.visualization.ColumnChart(document.getElementById('chart_div'));
        chart.draw(data, options);
    }
</script>

最后,我应该提一下,我的机器上没有安装php,但我的IDE上有一个php插件

提前感谢您提供任何帮助。 :)

0 个答案:

没有答案