0

我的课程有这个 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();
?> 
4

1 回答 1

0

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

$xml->writeAttribute('name', $row['name']);
$xml->writeAttribute('quantity', $row['quantity']);
$xml->writeAttribute('date', $row['date']);
$xml->writeAttribute('pending', $row['pending']);
于 2013-01-09T10:13:37.287 回答