Let's talk about json_encode usage. Usage of json_encode 1. the code for storing the data queried from the database in the array is as follows: $ querymysql_query ($ SQL); while ($ rowmysql_fetch_array ($ query )) {$ xdata [] $ row [Eve: Usage of json_encode
1. store the data queried from the database in an array.
The code is as follows:
$ Query = mysql_query ($ SQL );
While ($ row = mysql_fetch_array ($ query )){
$ Xdata [] = $ row ['eventdate'];
$ Ydata [] = intval ($ row ['data']);
}
2. convert data to json
The code is as follows:
$ Data_arr = array ($ xdata, $ ydata)
Json_encode ($ data_arr );
3. AJAX call data on the HTML page
The code is as follows:
$. Ajax ({
Type: "Get ",
Url: "columndata. php? R = "+ Math. floor (Math. random () * 1000 + 1 ),
Data: {'begintime': "" + BeginTime + "", "EndTime": "" + endTime + "", "keyword": "" + keyword + ""},
DataType: "text ",
Global: false,
Async: false,
Success: function (strReult ){
If (strReult = "-1") {alert ("fail! "); Return ;}
Var jsondata = eval ("(" + strReult + ")");
Var xData = jsondata [0];
Var yData = jsondata [1];
Var namestr = jsondata [2];
},
Error: function (){
Alert ("fail! ");
}
});
The above is all about the json_encode usage method. I hope it will be helpful to you.
Lifecycle 1. code for the data queried from the database in the array: $ query = mysql_query ($ SQL); while ($ row = mysql_fetch_array ($ query )) {$ xdata [] = $ row ['Eve...