[英]MySQL query into XML via PHP
我的課程中有此PHP,我想使用服務器端編程以XML格式動態生成帶有兩個表的訂單詳細信息的待處理訂單。 當我嘗試運行此命令時,出現錯誤(如下),並且我相信它來自查詢。 我是新手,無法弄清楚。 一些幫助將不勝感激! 謝謝!
XML解析錯誤:文檔元素后出現垃圾信息位置:hxxp://xxxx/xxxx/pending_details.php行號2,列1:
<?php
$con = mysql_connect("localhost", "root", "");
if (!$con) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db("eshop");
$query = "select product.name,order_details.quantity, order.date from product.id inner join order on order_details.order_id=order.id inner join product on order_details.product_id=product.id inner join customer on order.cust_id=costumer.id WHERE order.pending=>1";
$res = mysql_query($query);
$xml = new XMLWriter();
$xml->openURI("php://output");
$xml->startDocument();
$xml->setIndent(true);
$xml->startElement('pendings');
while ($row = mysql_fetch_assoc($res)) {
$xml->startElement("order");
$xml->writeAttribute('name', $row['product.name']);
$xml->writeAttribute('quantity', $row['order_details.quantity']);
$xml->writeAttribute('date', $row['order.date']);
$xml->writeAttribute('pending', $row['order.pending']);
$xml->endElement();
}
$xml->endElement();
header('Content-type: text/xml');
$xml->flush();
?>
嘗試僅使用這樣的名稱訪問該行
$xml->writeAttribute('name', $row['name']);
$xml->writeAttribute('quantity', $row['quantity']);
$xml->writeAttribute('date', $row['date']);
$xml->writeAttribute('pending', $row['pending']);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.