PHP array and JS interaction problem younger brother wants to use AJAX to fill data
$ SQL = "Select * from nation _fance where ". $ condition; $ rs = mysql_query ($ SQL, $ conn); $ index = 0; while ($ row = mysql_fetch_array ($ rs ))! = False) {$ result [$ index] = array ("PK" => $ row ["PK"], "NAME" => $ row ['name'], "SHORT_NAME" => $ row ['short _ name'], "NODE" => $ row ['node'], "PARENT_NODE" => $ row ['parent _ node']); $ index ++; // The following method cannot be used. is mysql_fetch_array an array returned? // $ Result [$ index] = $ row ;}
Please kindly advise, PHP + JQUERY, how to transmit data, how is it most convenient, and how to obtain it on the JS end. thank you...
Reply to discussion (solution)
$ Result [$ index] = $ row;
Why not? Only doubled the data. Does not affect usage
Finally, echo json_encode ($ result);. js can be interpreted.
Upstairs boss, I echo json_encode ($ result); this line of code is there.
How does JS read data? can you give an example?
It's not how JavaScript reads data, but what kind of data is required by js.
Difficulties cannot be left to others
Finally, echo json_encode ($ result);. js can be interpreted.
I am also a new student. Should you generate json?
Finally, echo json_encode ($ result);. js can be interpreted.
I am also a new student. Should you generate json?
Yes
$ Result [$ index] = $ row; this sentence is also acceptable. you can see it in print_r ($ result. It only contains the associated and index arrays at the same time.
Php and JS are of course the most convenient to transmit data in JSON. You can write as follows:
While ($ row = mysql_fetch_assoc ($ rs ))! = False ){
$ Result [] = $ row;
}
Echo json_encode ($ result );
Then JSON can be processed in JS.
The problem is not my code problem, it is a Chinese problem, it needs to be converted... everything is OK
$ Result = array ();
While ($ row = mysql_fetch_assoc ($ rs ))! = False ){
$ Result [] = array ("PK" => $ row ["PK"],
"NODE" => $ row ["NODE"],
"NAME" => iconv ("gb2312", "UTF-8", $ row ["NAME"])
);
}
Echo json_encode ($ result );