How does PHP say the query data returned by the database into the JSON data format

Source: Internet
Author: User
Inside the Zend frame.
$res = $db->query ("Select name from Job_type where tid= $type")->fetchall ();
I'm putting an array out of this thing:


Array (2) {[0]=> Array (1) {["Name"]=> string (6) "Mechanic"} [1]=> Array (1) {["Name"]=> string (6) "Pu"}}





Reply to discussion (solution)

Json_encode
Why don't you read the manual?

Json_encode

Inside the Zend frame.
$res = $db->query ("Select name from Job_type where tid= $type")->fetchall ();
I'm putting an array out of this thing:


Array (2) {[0]=> Array (1) {["Name"]=> string (6) "Mechanic"} [1]=> Array (1) {["Name"]=> string (6) "Pu"}}







I just do it, and then he can return to the JS JSON data format?

$res = $db->query ("Select name from Job_type where tid= $type")->fetchall ();


Json_encode ($res);
Echo $res;
Exit ();
And then in JS also did not write the data did not hit out, how can I view the specific format of the JSON data conversion, it is supposed to say how my data taken wrong, should also hit something out Ah, but nothing is the amount:

if (myxmlhttprequest.readystate==4) {
Alert ("return" +myxmlhttprequest.responsetext);
var Mes=myxmlhttprequest.responsetext;
var mes_obj=eval ("(" +mes+ ")");
for (Var i=0,mes_obj.length;i++) {

Alert (mes_obj[i].[ Name]);

}


}







$res =json_encode ($res);
Echo $res;
Exit ();

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.