Why can I use PHP to write data to an XML file in a word table to read only one piece of data?

Source: Internet
Author: User
For help, PHP writes an XML file, and the word table reads only one piece of data. Why does PHP display only one piece of mxl file data generated from the table based on the type traversal in the main table?

Include ("admin. php ");
If (file_exists ("../xml/list. xml "))
{
Unlink ("../xml/list. xml"); // if it exists, delete it first.
}
// Create doctype header
$ Dom = new DOMDocument ("1.0", "UTF-8 ");
// Create root element
$ Root = $ dom-> createElement ("list ");
$ Dom-> appendChild ($ root );
$ Dom-> formatOutput = true;

$ SqlClass = "select music_class from dj_class"; // read data from the database
$ ResClass = mysql_query ($ sqlClass );
While ($ rowClass = mysql_fetch_array ($ resClass ))
{
$ Music_class = $ rowClass ['Music _ class']; // read a field

$ Item = $ dom-> createElement ("m ");
$ Root-> appendChild ($ item );

$ Item_url = $ dom-> createAttribute ("label ");
$ Item-> appendChild ($ item_url );
$ Item_urlValue = $ dom-> createTextNode ($ music_class );
$ Item_url-> appendChild ($ item_urlValue );


$ Item_urlx = $ dom-> createElement ("m ");
$ Item-> appendChild ($ item_urlx );


Echo "$ music_class ";
Echo"
";
Echo "";
$ SqlMusic = "select * from dj_music where music_ishtml = '$ music_class'"; // read data from the database

$ ResMusic = mysql_query ($ sqlMusic );


$ Sqlc = "select count (*) AS count FROM dj_music where music_ishtml = '$ music_class '";
$ Result = mysql_fetch_array (mysql_query ($ sqlc ));
$ Count = $ result ['count'];


// Echo "$ count ";
// Echo"
";



If ($ count> 0) {// check whether data exists here



For ($ I = 0; $ I <$ count; $ I ++)
{
While ($ rowMusic = mysql_fetch_row ($ resMusic ))
{
Echo "$ rowMusic [1]";
Echo "$ rowMusic [2]";

Echo"
";

$ Item_url = $ dom-> createAttribute ("type ");
$ Item_urlx-> appendChild ($ item_url );
$ Item_urlValue = $ dom-> createTextNode ("");
$ Item_url-> appendChild ($ item_urlValue );

$ Item_url = $ dom-> createAttribute ("src ");
$ Item_urlx-> appendChild ($ item_url );
$ Item_urlValue = $ dom-> createTextNode ($ music_url );
$ Item_url-> appendChild ($ item_urlValue );

$ Item_url = $ dom-> createAttribute ("lrc ");
$ Item_urlx-> appendChild ($ item_url );
$ Item_urlValue = $ dom-> createTextNode ("$ rowMusic [2]");
$ Item_url-> appendChild ($ item_urlValue );

$ Item_url = $ dom-> createAttribute ("label ");
$ Item_urlx-> appendChild ($ item_url );
$ Item_urlValue = $ dom-> createTextNode ("$ rowMusic [1]");
$ Item_url-> appendChild ($ item_urlValue );

}

}

} Else {
Echo "no data ";
Echo"
";
}

}

// Save tree to file
$ Dom-> save ("../xml/list. xml"); // save it to the specified directory
// Header ("location: content_show.php ");
?>



Php output:

Tiao Online Game Association
Wwww
Haomen webgame Association
Tick ../xml/music/Swordsman
Legend of Phoenix ../xml/music/Swordsman
Slab
A sword is like a dream ../xml/music/sword is like a dream

If xml is generated














The correct XMl is as follows:


















Please kindly advise. thank you for your help.










Reply to discussion (solution)

Because $ item_urlx = $ dom-> createElement ("m"); is outside the loop, there is actually only one

Regardless of the number of cycles, the subsequent values overwrite the previous values, and only one node is generated.

Thank you for solving the problem.

Related Article

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.