php - SQL导出到 XML usting php脚本 ( 客户出口)

  显示原文与译文双语对照的内容
0 0

我的查询结果有问题。 运行这里命令时,它会在批处理中查询所有内容。 我需要从每个客户中得到一个新的头。

我认为问题是从第 143行到 179.

if (!$_HTTP_POST_VARS["separator"])
$sep= str_replace('t',"11", $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_faxn";
$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>
时间:原作者:6个回答

0 0

你正在使用concatenate运算符,因此它将在所有查询结果中生成一个长字符串:

$customers_id.=$row['customers_id'];

你可能希望将这些数据放入 array 中:

$customer['id'][$key] = $customers_id.=$row['customers_id'];
原作者:
0 0

你的错误是连接所有行的结果。 循环

while ($row = tep_db_fetch_array($customers_query))

应该用于输出像

echo"
 <head>
 <Kundenr>$row[customers_id]</Kundenr>
. . .
 </head>
";

请更改你的header,以匹配实际内容类型( 这不是你的问题的原因,而是重要的):

header("Content-type: text/xml; charset=ISO-8859-1");
原作者:
...