PHP寫入XML檔案事字表資料唯讀一條資料,什麼原因

來源:互聯網
上載者:User
求助PHP寫入XML檔案事字表資料唯讀一條資料,什麼原因
PHP根據主表中類型遍曆從表對於資料 產生mxl 檔案資料只顯示一條 具體如下

include("admin.php");
if(file_exists("../xml/list.xml"))
{
unlink("../xml/list.xml");//存在就先刪除
}
// create doctype頭
$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";//從資料庫裡讀資料
$resClass = mysql_query($sqlClass);
while($rowClass = mysql_fetch_array($resClass))
{
$music_class = $rowClass['music_class'];//讀取欄位

$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'";//從資料庫裡讀資料

$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){//此處判斷是否有資料



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 "無資料";
echo "
";
}

}

// save tree to file
$dom->save("../xml/list.xml");//儲存到指定目錄下
//header("location:content_show.php");
?>



php 輸出結果為

天傲網遊公會
wwww
豪門網遊公會
滴答../xml/music/刀劍如夢.mp3
鳳凰傳奇../xml/music/刀劍如夢.mp3
散人天堂公會
刀劍如夢../xml/music/刀劍如夢.mp3

產生xml則是






  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.