[英]SQL export to XML. usting php script. (customer export)
查询结果有问题。 当我运行它时,它批量查询所有内容。 我需要从每个客户那里重新树立头。
我认为问题出在143至179行。
if (!$_HTTP_POST_VARS["separator"])
$sep= str_replace('\t', "\011", $sep);
//$contents="customers_id".$sep."customers_lastname".$sep."customers_firstname".$sep."customers_email_address".$sep."customers_gender".$sep."customers_dob".$sep."entry_company".$sep."entry_street_address".$sep."entry_postcode".$sep."entry_city".$sep."entry_state".$sep."entry_suburb".$sep."countries_name".$sep."customers_telephone".$sep."customers_fax\n";
$customers_query_raw = "select c.customers_id,
c.customers_lastname,
c.customers_firstname,
c.customers_email_address,
c.customers_gender,
c.customers_dob,
c.customers_telephone,
c.customers_fax,
a.entry_company,
a.entry_street_address,
a.entry_postcode,
a.entry_city,
a.entry_state,
a.entry_suburb,
co.countries_name
from " . TABLE_CUSTOMERS . " c left join " . TABLE_ADDRESS_BOOK . " a on c.customers_id = a.customers_id and c.customers_default_address_id = a.address_book_id
left join " . TABLE_COUNTRIES . " co on co.countries_id = a.entry_country_id
WHERE c.customers_id >= 4150 and c.customers_id <= 4200";
$customers_query = tep_db_query($customers_query_raw) or die(mysql_error());
while ($row = tep_db_fetch_array($customers_query)) {
$customers_id.=$row['customers_id'];
$customers_lastname.=$row['customers_lastname'];
$customers_firstname.=$row['customers_firstname"'];
$customers_email_address.=$row['customers_email_address'];
$customers_gender.=$row['customers_gender'];
$customers_dob.=$row['customers_dob'];
$entry_company.=$row['entry_company'];
$entry_street_address.=$row['entry_street_address'];
$entry_postcode.=$row['entry_postcode'];
$entry_city.=$row['entry_city'];
$entry_state.=$row['entry_state'];
$entry_suburb.=$row['entry_suburb'];
$countries_name.=$row['countries_name'];
$customers_telephone.=$row['customers_telephone'];
$customers_fax.=$row['customers_fax'];
}
/*print('<?xml version="1.0" encoding="ISO-8859-1" ?>');*/
header("Content-type: text/html; charset=ISO-8859-1");
header("Content-disposition: attachment; filename=ordre_export_" . date("Ymd") . ".xml");
header("Content-type: application/octet-stream; charset=iso-8859-1");
echo '<?xml version="1.0" encoding="iso-8859-1"?>
<!-- -->
<Root xmlns:dt="urn:schemas-microsoft-com:datatypes">
';
echo "
<head>
<Kundenr>$customers_id</Kundenr>
<Company>$entry_company</Company>
<Kundenavn>$customers_lastname </Kundenavn>
<Adresse>$entry_street_address</Adresse>
<Adresse2> </Adresse2>
<Postnr>$entry_postcode</Postnr>
<Poststed>$entry_city</Poststed>
<Landkode> </Landkode>
<Land>$countries_name</Land>
<customers_telephone>$customers_telephone</customers_telephone>
<fax>$customers_fax</fax>
<mail>$customers_email_address</mail>
<dob>$customers_dob</dob>
<Fritekst></Fritekst>
<Kommentarer></Kommentarer>
</head>
";
$j++;
echo "
</Root>";
die();
}
require(DIR_WS_INCLUDES . 'application_bottom.php');
?>
样本如何显示出来。 我的客户ID为4位数字。 因此,它应该在4150之后刹车,并开始一个新的XML块。
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- -->
<Root xmlns:dt="urn:schemas-microsoft-com:datatypes">
<head>
<Kundenr>41504151415241534154415541564157415841594160416141670417</Kundenr>
您正在使用连接运算符,因此它将所有查询结果组成一个很长的字符串:
$customers_id.=$row['customers_id'];
您可能希望将这些数据放入数组中:
$customer['id'][$key] = $customers_id.=$row['customers_id'];
您的错误是连接所有行的结果。 环
while ($row = tep_db_fetch_array($customers_query))
应该用于输出XML条目,例如
echo "
<head>
<Kundenr>$row[customers_id]</Kundenr>
...
</head>
";
请同时更改标题以匹配实际的内容类型(这不是造成问题的原因,但很重要):
header("Content-type: text/xml; charset=ISO-8859-1");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.