Let's talk about json_encode usage and json_encode. Let's talk about json_encode usage. let's talk about json_encode1. copy the code from the database data in the array: $ querymysql_query ($ SQL); while ($ rowmysql_fetch_a: Talk about json_encode usage;
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. the code of the data queried from the database in the array is as follows: $ query = mysql_query ($ SQL); while ($ row = mysql_fetch_a...