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.