列の合計を取得して JSON で解析しようとしています。
私が使用する合計を取得するには:
SELECT SUM(price) FROM `Fuelconsumption` WHERE `date` like '%09-2012%'
このコマンドを SQL Server で直接使用すると、Figure の結果が得られますが、JSON で解析しようとすると機能しません。
これが私のJSONとPHPコードです:
case 'getstats':
                    $query="SELECT SUM(price) FROM `Fuelconsumption` WHERE `date` like '%09-2012%'";
                    $result = mysql_query($query);
                    $json = array();
                        while($row = mysql_fetch_array($result))
                        {
                                $json['price']=$row['price'];
                        }
                        print json_encode($json);
                    mysql_close();
    break;
そして、これは私のJSです:
xmlhttp = new XMLHttpRequest()
xmlhttp.onreadystatechange = function () {
    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
        var jsontext = xmlhttp.responseText;
        var json = JSON.parse(jsontext);
        console.log(jsontext)
    }
}
xmlhttp.open("GET", "mysql.php?p=getstats" + "&date=09-2012", true);
xmlhttp.send();