Novice ask a about PHP from the database after obtaining data how to populate the XML file

Source: Internet
Author: User
Novice ask a question about how to populate the XML file after PHP gets the data from the database
Demand:
I know the user ID, according to the user ID query the relevant information of the user, the background SQL statement has been written well, is now in the logical layer through the node way to populate the data into XML, and then through the previous JS code to obtain data, please help me to see what I wrote this logic layer code what is the problem,
PHP Code
  Reference database Processing file require_once ". /.. /dbhandle/dbhandle/dbuser.php "; $lefNav = $_request [" Lefnav "]; $action = $_request [" Action "];if ($lefNav = =" UserInfo ")        {if (action = = "Init") {$userId = $_request [' user_id '];        $rs = Dbuser::getuserinfobyid ($userId);            if ($RS) {//The result of the queried user information is placed in the XML to the previous paragraph $doc = new DOMDocument ("1.0", "Utf-8");                            $doc->appendchild ($doc->createelement ("xml"));                                $userNode = $doc->createelement ("RS");                $userId = $doc->createelement ("UserId");                $userIdTx = $doc->createtextnode ($rs [0]);                                $userId->appendchild ($userIdTx);                $name = $doc->createelement ("name");                $nameTx = $doc->createtextnode ($rs [1]);                                $name->appendchild ($nameTx);                $rname = $doc->createelement ("Rname"); $rnameTx = $doc->createtextnode ($rs [2]);                                $rname->appendchild ($rnameTx);                $gname = $doc->createelement ("Gname");                $gnameTx = $doc->createtextnode ($rs [3]);                                $gname->appendchild ($gnameTx);                $userNode->appendchild ($userId);                $userNode->appendchild ($name);                $userNode->appendchild ($rname);                                $userNode->appendchild ($gname);                $doc->documentelement->appendchild ($userNode);                    echo $doc->savexml ();        } else {echo "FAIL";    }    }}


------Solution--------------------
PHP-to-XML conversion encapsulation function: xmlparse.php
PHP Code
Include (DirName (__file__). /xmlparse.php "); $listtags = Explode (" "," 2 Name "), $arr = Array (1," name "=" SOM "," admin ", 100,array (" name "=" TOM ") , "Lily")); $contXML = Dump_xml_config ($arr, "xml", "Utf-8");//Put File//file_put_contents_safe ("/path/test.xml", $ Contxml, "w"); echo $contXML; #源码 # # # # #
  
   
  
   
        <0>1
   
     #    
   
    
     
    SOM
   
    #    <1>admin #
   
        <2>100
   
     #    <3>#        
   
    
     
    TOM #
   
    
   
        
   
     <0>lily
  
    # #
  • 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.