Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/55.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用PHP实现Mysql到XML的转换_Php_Mysql_Xml - Fatal编程技术网

用PHP实现Mysql到XML的转换

用PHP实现Mysql到XML的转换,php,mysql,xml,Php,Mysql,Xml,我的桌子的idİ信息1-2-3 当我尝试跑步时,我看到了最后一个值。 我想看到所有的价值观 <?php $host = "localhost"; //mysql adresi $user = "root"; //veritabanı kullanıcı adı $pass = ""; //veritabanı kullanıcı şifresi $database = "yemekcim"; //veritabanı adı $linkID = m

我的桌子的idİ信息1-2-3 当我尝试跑步时,我看到了最后一个值。 我想看到所有的价值观

<?php
$host = "localhost";   //mysql adresi
    $user = "root";  //veritabanı kullanıcı adı
    $pass = "";  //veritabanı kullanıcı şifresi
    $database = "yemekcim";  //veritabanı adı
    $linkID = mysql_connect($host, $user, $pass) or die("Veritabanına bağlanılamadı.");  //bağlantı kuruluyor
    mysql_select_db($database, $linkID) or die("Veritabanı bulunamadı.");
     $query="select * from mekan_menu_icerik";
    $resultID = mysql_query($query, $linkID) or die("Veri bulunamadı.");

    while($data = mysql_fetch_assoc($resultID)) {

     $newsXML = new SimpleXMLElement("<firmabilgi></firmabilgi>");
$newsXML->addAttribute('newsPagePrefix', $data["id"]);
$newsIntro = $newsXML->addChild('content');
$newsIntro->addAttribute('type', 'latest'); 

    }
Header('Content-type: text/xml');
echo $newsXML->asXML();

?>
addAttribute('newsPagePrefix',$data[“id]”);
$newsIntro=$newsXML->addChild('content');
$newsIntro->addAttribute('type','latest');
}
标题('Content-type:text/xml');
echo$newsXML->asXML();
?>

您只回显最后一个值,因为您已将实际的“回显”放在while语句之外


要显示所有这些内容,您应该在调用addAttribute()之后的while内进行回显。

您需要在
之前移动
$newsXML=new simplexmlement(…)
,而
开始执行此操作。但是“文档末尾的额外内容”请查看