新手请问一个关于PHP 从数据库取得数据后怎么填充到XML文件中
新手请教一个关于PHP 从数据库取得数据后如何填充到XML文件中
需求:
我已知用户ID,根据用户ID查询该用户的相关信息,后台SQL语句已经写好,现在是在逻辑层中通过节点方式将数据填充到XML中,然后再通过前段JS代码取得数据, 麻烦请各位牛牛们帮我看下我写的这个逻辑层代码有什么问题,
- PHP code
<!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ -->// 引用数据库处理文件 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) { // 将查询出来的用户信息结果放置到XML中传到前段 $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"; } } }
------解决方案--------------------
PHP与XML的相互转换封装函数: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"); //放入文件 //file_put_contents_safe("/path/test.xml",$contXML,"w"); echo $contXML; #源码 #<?xml version="1.0" encoding="utf-8"?> #<xml> # 10> # <name>SOM</name> # admin1> # 1002> # # <name>TOM</name> # Lily0> # 3> #</xml> <div class="clear"> </div>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Many users will choose the Huawei brand when choosing smart watches. Among them, Huawei GT3pro and GT4 are very popular choices. Many users are curious about the difference between Huawei GT3pro and GT4. Let’s introduce the two to you. . What are the differences between Huawei GT3pro and GT4? 1. Appearance GT4: 46mm and 41mm, the material is glass mirror + stainless steel body + high-resolution fiber back shell. GT3pro: 46.6mm and 42.9mm, the material is sapphire glass + titanium body/ceramic body + ceramic back shell 2. Healthy GT4: Using the latest Huawei Truseen5.5+ algorithm, the results will be more accurate. GT3pro: Added ECG electrocardiogram and blood vessel and safety

Why Snipping Tool Not Working on Windows 11 Understanding the root cause of the problem can help find the right solution. Here are the top reasons why the Snipping Tool might not be working properly: Focus Assistant is On: This prevents the Snipping Tool from opening. Corrupted application: If the snipping tool crashes on launch, it might be corrupted. Outdated graphics drivers: Incompatible drivers may interfere with the snipping tool. Interference from other applications: Other running applications may conflict with the Snipping Tool. Certificate has expired: An error during the upgrade process may cause this issu simple solution. These are suitable for most users and do not require any special technical knowledge. 1. Update Windows and Microsoft Store apps

Part 1: Initial Troubleshooting Steps Checking Apple’s System Status: Before delving into complex solutions, let’s start with the basics. The problem may not lie with your device; Apple's servers may be down. Visit Apple's System Status page to see if the AppStore is working properly. If there's a problem, all you can do is wait for Apple to fix it. Check your internet connection: Make sure you have a stable internet connection as the "Unable to connect to AppStore" issue can sometimes be attributed to a poor connection. Try switching between Wi-Fi and mobile data or resetting network settings (General > Reset > Reset Network Settings > Settings). Update your iOS version:

Doc is a file in document format; doc is the abbreviation of Document, which represents graphic and text content and can be opened using Word of the office software Office. This format was originally used for plain text files and is more common in different operating systems. Software and hardware Instructions for use.

We know that Java supports three types of comments, namely single-line comments, multi-line comments and document comments. Let’s take a look at what they look like //Single-line comments/*Multi-line comments*//***@...*.. ..*Documentation Comments*/ Many newbies may not understand, what is the use of writing these comments? In fact, it is because beginners have a small amount of code and can quickly search and modify it without comments. When the code gradually increases, comments are a good thing, not only so that you can clearly see the code, but also to develop projects with you. It is convenient for members to remember and get rid of the bad habit of not writing comments! ! ! So, here comes our topic today, what are Doc comments? javadoc is a technology provided by Sun. It starts from the program

GoogleDocs is so simple that now everyone can complete their document work through GoogleDocs instead of traditional document editors like Microsoft Word. There are many advantages to using Google Docs, you can access your documents from anywhere in the world with just an internet connection and computer connection. You don't need to preinstall software on your computer, and you don't need to compromise on space to store the files you create. However, not everyone likes to just go with the flow and keep up to date with modern technology. We all like to be lazy sometimes, and if you're a Microsoft Word lover, that's totally fine. But when you're a GoogleDocs guy and you're working with

php提交表单通过后,弹出的对话框怎样在当前页弹出php提交表单通过后,弹出的对话框怎样在当前页弹出而不是在空白页弹出?想实现这样的效果:而不是空白页弹出:------解决方案--------------------如果你的验证用PHP在后端,那么就用Ajax;仅供参考:HTML code

TypeError:Failedtoexecute'appendChild'on'Node' in Vue, how to solve it? In Vue development, various errors are often encountered. One of the common errors is "TypeError:Failedtoexecute'appendChild'on'Node'". This error usually occurs during the dynamic generation of DOM elements, meaning that Vue cannot
