我正在尝试创建一个具有MySQL查询输出的CSV文件。 我遇到的问题是,对于其中一个列,我有多个与“entity_id”关联的字段,因此它复制了只有“value”字段不同的行。相反,我希望将“值”字段放在CSV中与其他相关信息位于同一行的新列中。
以下是代码的相关部分:
$sqlQuery = mysql_query('SELECT `sales_flat_order`.`increment_id` , `sales_flat_order`.`created_at` , `sales_flat_order`.`status` , `sales_flat_order`.`shipping_amount` , `sales_flat_order`.`grand_total` , `sales_flat_order`.`shipping_description` , `sales_flat_order`.`customer_email` , `sales_flat_order`.`customer_note` , `sales_flat_order_item`.`item_id` , `sales_flat_order_item`.`sku` , `sales_flat_order_item`.`qty_ordered` , `sales_flat_order_item`.`row_total` , `sales_flat_order`.`customer_firstname` , `sales_flat_order`.`customer_lastname`, `street`, `city`, `region`,`postcode`, `country_id`, `telephone`, `company`, `aitoc_order_entity_custom`.`value`
FROM sales_flat_order
INNER JOIN `sales_flat_order_item` ON `sales_flat_order`.`entity_id` = `sales_flat_order_item`.`order_id`
INNER JOIN `sales_flat_quote_item` ON `sales_flat_order_item`.`quote_item_id` = `sales_flat_quote_item`.`item_id`
INNER JOIN `sales_flat_quote_address` ON `sales_flat_quote_item`.`quote_id` = `sales_flat_quote_address`.`quote_id`
LEFT OUTER JOIN `aitoc_order_entity_custom` ON `sales_flat_order`.`entity_id` = `aitoc_order_entity_custom`.entity_id`
WHERE `sales_flat_order`.`status` != "Complete" AND `sales_flat_quote_address`.`address_type` = "shipping" AND `sales_flat_order_item`.`row_total` != "0"');
// output the information
while ($queryRows = mysql_fetch_assoc($sqlQuery)) fputcsv($outputFile, $queryRows);