Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 我的服务器配置能否阻止json工作?_Php_Mysql_Json_Highcharts - Fatal编程技术网

Php 我的服务器配置能否阻止json工作?

Php 我的服务器配置能否阻止json工作?,php,mysql,json,highcharts,Php,Mysql,Json,Highcharts,我正在努力完成一个关于从MySQL获取JSON字符串并为highcharts做准备的教程,但它不起作用,我不知道为什么 HTML: <script type="text/javascript" src="js/jquery.min.js"></script> <script type="text/javascript"> $(function () { var chart; $(document).ready(funct

我正在努力完成一个关于从MySQL获取JSON字符串并为highcharts做准备的教程,但它不起作用,我不知道为什么

HTML:

<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript">
    $(function () {
        var chart;
        $(document).ready(function () {
            $.getJSON("data.php", function (json) {

                chart = new Highcharts.Chart({
                    chart: {
                        renderTo: 'container',
                        type: 'line',
                        marginRight: 130,
                        marginBottom: 25
                    },
                    title: {
                        text: 'Revenue vs. Overhead',
                        x: -20 //center
                    },
                    subtitle: {
                        text: '',
                        x: -20
                    },
                    xAxis: {
                        categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
                    },
                    yAxis: {
                        title: {
                            text: 'Amount'
                        },
                        plotLines: [
                            {
                                value: 0,
                                width: 1,
                                color: '#808080'
                            }
                        ]
                    },
                    tooltip: {
                        formatter: function () {
                            return '<b>' + this.series.name + '</b><br/>' +
                                this.x + ': ' + this.y;
                        }
                    },
                    legend: {
                        layout: 'vertical',
                        align: 'right',
                        verticalAlign: 'top',
                        x: -10,
                        y: 100,
                        borderWidth: 0
                    },
                    series: json
                });
            });

        });

    });
</script>
</head>
<body>
<script src="js/highcharts.js"></script>
<script src="js/exporting.js"></script>

<div id="container" style="min-width: 400px; height: 400px; margin: 0 auto"></div>
<?php
$con = mysql_connect("*****", "*****", "*****");

if (!$con) {
    die('Could not connect: ' . mysql_error());
}

mysql_select_db("*****", $con);

$sth = mysql_query("SELECT revenue FROM projections_sample");
$rows = array();
$rows['name'] = 'Revenue';
while ($r = mysql_fetch_array($sth)) {
    $rows['data'][] = $r['revenue'];
}

$sth = mysql_query("SELECT overhead FROM projections_sample");
$rows1 = array();
$rows1['name'] = 'Overhead';
while ($rr = mysql_fetch_assoc($sth)) {
    $rows1['data'][] = $rr['overhead'];
}

$result = array();
array_push($result, $rows);
array_push($result, $rows1);

print json_encode($result, JSON_NUMERIC_CHECK);

mysql_close($con);
?>
我假设我的连接细节是正确的,因为如果我故意输入错误的密码,我会得到MySQL连接错误

“Could not connect: Access denied for user ‘*****’@'localhost’ (using password: YES)”
另外,当我在页面底部添加echo@mysql_ping()?'True':'false';“时,返回了
“True”


因为我确信它应该可以工作,我想知道是否有任何与服务器配置相关的东西会阻止我使用JSON?

如果你不能使用
JSON\u NUMERIC\u CHECK
(因为它需要PHP5.3.3())

您可以转到
int
[
$number=(int)“1234”
]


必须:将禁用
mysql.*
函数。不建议编写新代码,因为它将在将来被删除。在执行查询后,请检查mysql错误:
$result=mysql\u query(“从投影中选择开销\u示例”);如果(!result)打印mysql\u错误
这是调试的第一步..当您打印json编码的数据时,实际打印的是什么?尝试将
警报(json)
添加到javascript中,看看它是否返回有效的json!php只是给了我一个空白的白页atm@JasonMcCreary如果我一开始就不能让代码正常工作,那么我认为让代码符合当前标准没有多大意义。一个多星期以来,我一直试图从各种教程中获得json输出@当我添加
$result=mysql\u查询(“从投影中选择开销\u样本”)时,我得到一个空白页;如果(!result)打印mysql\u错误与未添加时相同@MichaelWheeler我应该把
警报(json)
放在哪里。sry我对java一窍不通。我给了你糟糕的代码。应该是
print mysql_error()
但是@MichaelWheeler的建议对于调试javascript接收到的内容很好。你会想把它放在getJSON方法之后:
$.getJSON(“data.php”,function(json){alert(json)…
太棒了,我花了很多时间试图解决这个问题。从这个练习中也学到了不少东西。真是太感谢你了……)
“Could not connect: Access denied for user ‘*****’@'localhost’ (using password: YES)”
while ($r = mysql_fetch_array($sth)) {
    $rows['data'][] = (int)$r['revenue']; // <- (int)
}
while ($rr = mysql_fetch_assoc($sth)) {
    $rows1['data'][] = (int)$rr['overhead']; // <- (int)
}
print json_encode($result);