Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/375.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从MySql获取JSON格式到javascript_Javascript_Php_Mysql_Json_Amcharts - Fatal编程技术网

使用PHP从MySql获取JSON格式到javascript

使用PHP从MySql获取JSON格式到javascript,javascript,php,mysql,json,amcharts,Javascript,Php,Mysql,Json,Amcharts,我想使用PHP从SQL数据库中获取json格式 下面是mySql数据库的一个捕获 data.php <?php include("include/connexion.php"); $requete = "SELECT * from statistika"; $resultat = mysql_query( $requete ) or die( mysql_error() ); $rows = array(); $total_vue = 0;

我想使用PHP从SQL数据库中获取json格式

下面是mySql数据库的一个捕获

data.php

<?php  include("include/connexion.php");
$requete = "SELECT * from statistika";
$resultat = mysql_query( $requete ) or die( mysql_error() );
$rows = array(); 
$total_vue = 0;
<?php
 include("data.php");
 echo  json_encode($rows);
?>
json_encode.php

<?php  include("include/connexion.php");
$requete = "SELECT * from statistika";
$resultat = mysql_query( $requete ) or die( mysql_error() );
$rows = array(); 
$total_vue = 0;
<?php
 include("data.php");
 echo  json_encode($rows);
?>
现在我想将JSON格式传递给javascript,我正在使用以下代码

var foo = {};
foo.toString = function () { return <?php echo json_encode($rows);?> };
document.write(foo.toString);
我不希望
函数(){return
出现在输出中!!!

有什么提示吗


谢谢。

在JS代码中更改这一行

foo.toString=function(){return};

foo.toString='';
var foo={};
foo.toString=函数(){return};
document.write(foo());

您正在创建foo as函数,因此像这样调用您将只得到json。

首先,我建议您不要将
javascript
php
代码混合在一个文件中。这是一种非常糟糕的样式。否则,在某一时刻,您将得到一些糟糕的spagetti代码。您最好从ajax调用中获得这些json数据。只需分而治之,正如他们所说的。谢谢,我想用amcharts库中的数据…你以前用过这个库吗?
function () { return [{"date":1439769600000,"value":"5"},{"date":1439787600000,"value":"12"},{"date":1439806631000,"value":"8"},{"date":1439821320000,"value":"18"},{"date":1439919642000,"value":"6"},{"date":1439889752000,"value":"2"},{"date":1439893260000,"value":"20"},{"date":1439906400000,"value":"9"},{"date":1429308000000,"value":"15"},{"date":1421535600000,"value":"12"},{"date":1413583200000,"value":"18"},{"date":1405634400000,"value":"6"},{"date":1439828640000,"value":"14"},{"date":1439935200000,"value":"19"},{"date":1439863200000,"value":"12"},{"date":1439884800000,"value":"18"},{"date":1439917200000,"value":"26"},{"date":1439920800000,"value":"4"},{"date":1439904320000,"value":"0"},{"date":1439907420000,"value":"1"},{"date":1439907428000,"value":"1"},{"date":1439907434000,"value":"3"},{"date":1439907437000,"value":"1"},{"date":1439907447000,"value":"8"},{"date":1439907452000,"value":"3"},{"date":1439907459000,"value":"5"},{"date":1439907469000,"value":"8"},{"date":1439907482000,"value":"10"},{"date":1439907507000,"value":"21"},{"date":1439907510000,"value":"1"},{"date":1439907519000,"value":"7"},{"date":1439907526000,"value":"5"},{"date":1439907547000,"value":"18"},{"date":1439907557000,"value":"8"},{"date":1439907560000,"value":"1"},{"date":1439907576000,"value":"3"},{"date":1439907581000,"value":"3"},{"date":1418857200000,"value":"300"},{"date":1426633200000,"value":"450"},{"date":1434578400000,"value":"500"},{"date":1424214000000,"value":"600"}] 
foo.toString = function () { return <?php echo json_encode($rows);?> };
foo.toString = '<?php echo json_encode($rows);?>';
var foo = {};
foo.toString = function () { return <?php echo json_encode($rows);?> };
document.write(foo());