MySQL通过PHP查询到XML

时间:2022-09-25 15:55:37

I have this PHP for my coursework and I want to use server-side programming to dynamically produce in XML format the pending orders with order details of two tables. When I try to run this I get an error (below) and I believe it comes from the query. I'm and newbie and can't figure it out. Some help would be much appreciated! Thank you!

我有这个PHP用于我的课程,我想使用服务器端编程以XML格式动态生成具有两个表的订单详细信息的挂单。当我尝试运行这个时,我得到一个错误(下面),我相信它来自查询。我和新手都无法理解。一些帮助将不胜感激!谢谢!

XML Parsing Error: junk after document element Location: hxxp://xxxx/xxxx/pending_details.php Line Number 2, Column 1:

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();
?> 

1 个解决方案

#1


0  

try to access to the row only with the name like this

尝试只使用这样的名称访问该行

$xml->writeAttribute('name', $row['name']);
$xml->writeAttribute('quantity', $row['quantity']);
$xml->writeAttribute('date', $row['date']);
$xml->writeAttribute('pending', $row['pending']);

#1


0  

try to access to the row only with the name like this

尝试只使用这样的名称访问该行

$xml->writeAttribute('name', $row['name']);
$xml->writeAttribute('quantity', $row['quantity']);
$xml->writeAttribute('date', $row['date']);
$xml->writeAttribute('pending', $row['pending']);