The following script produces the txt file with the required data, but it produces the data twice in the text file.
mysql_connect($hostname_MySQLCon, $username_MySQLCon, "") or die(mysql_error());
mysql_select_db($database_MySQLCon) or die(mysql_error());
$data = mysql_query("
SELECT sales_flat_order.increment_id, sales_flat_order.gift_message_id, sales_flat_order.status, gift_message.gift_message_id, gift_message.message
FROM sales_flat_order
JOIN gift_message ON sales_flat_order.gift_message_id = gift_message.gift_message_id
WHERE sales_flat_order.gift_message_id IS NOT NULL
GROUP BY sales_flat_order.increment_id
/* AND sales_flat_order.status = 'pending' */;")
or die(mysql_error());
while($result = mysql_fetch_array( $data ))
{
$dataRow[] = implode("|", $result);
}
$theFile = 'orders-meta.txt';
if (!$handle = fopen($theFile, 'a')) {
exit;}
if (fwrite($handle, implode("
", $dataRow)) === FALSE) {
echo "Cannot write to file ($theFile)";
exit;}
echo "Success, the file was written.";
fclose($handle);
Example output in the txt file:
100000001|100000001|1121|1121|pending|pending|1121|gift message|gift message
100000002|100000002|1123|1123|pending|pending|1123|Gift message|Gift message
Why would it be producing each value twice? And how can I change it so that output would be:
100000001|1121|pending|1121|gift message
100000002|1123|pending|1123|Gift message
Really appreciate any help.
Thanks