I'm trying to produce a tab delimited file output will be able to use to load into quickbooks. I'm while using following code on for that header.

header("Content-type: text/plain");
header("Content-Disposition: attachment; filename=\"my-data.txt\"");

I've two problems.

The very first is that a few of the submissions are text but includes a comma , inside it (and that's why I had been using tab delimited. SQL (kindly) puts "" around individuals fields for me personally, which in turn get transfered towards the text file and therfore subsequently in to the accounts package. I cant observe how I dissuade SQL from doing that or how you can strip it from the content from the text file.

Next, the very first output within the script is definitely an echo statement then a tab etc The particular output however consists of an additional row in the begining (I can tell that the ASCII 0A continues to be placed) I cant see where that's originating from?

I've attached the code I'm using just in case I'm missing something apparent.

Help

Thank you

<?php
header("Content-type: text/plain");
header("Content-Disposition: attachment; filename=\"my-data.txt\"");
// Open standard includes 
include ('./includes/protect.php');  //User name and password control
require_once('Connections/Dragonnet.php');
mysql_select_db($database_Dragonnet, $Dragonnet);  //Connect to database
?>

<?php

$batch1 =  $_GET["batch1"];
$batch2 =  $_GET["batch2"];
$query =  "SELECT invtrans.StdInvNar1 AS 'invtrans StdInvNar1',
                  invtrans.StdInvNar2 AS 'invtrans StdInvNar2',
                  invtrans.StdInvNar3 AS 'invtrans StdInvNar3',
                  invtrans.StdInvNar4 AS 'invtrans StdInvNar4',
                  invtrans.StdInvNar5 AS 'invtrans StdInvNar5',
                  invtrans.StdInvNar6 AS 'invtrans StdInvNar6',
                  invtrans.StdInvNar7 AS 'invtrans StdInvNar7',
                  invtrans.StdInvNar8 AS 'invtrans StdInvNar8',
                  invtrans.StdInvNar9 AS 'invtrans StdInvNar9',
                  invtrans.StdInvNar10 AS 'invtrans StdInvNar10',
                  invtrans.InvNar1 AS 'invtrans InvNar1',
                  invtrans.InvNar2 AS 'invtrans InvNar2',
                  invtrans.InvNar3 AS 'invtrans InvNar3',
                  invtrans.InvNar4 AS 'invtrans InvNar4',
                  invtrans.InvNar5 AS 'invtrans InvNar5',
                  invtrans.InvNar6 AS 'invtrans InvNar6',
                  invtrans.InvNar7 AS 'invtrans InvNar7',
                  invtrans.InvNar8 AS 'invtrans InvNar8',
                  invtrans.InvNar9 AS 'invtrans InvNar9',
                  invtrans.InvNar10 AS 'invtrans InvNar10',
                  invtrans.Charge AS 'invtrans Charge',
                  invtrans.Cost AS 'invtrans Cost',
                  invtrans.VATtype AS 'invtrans VATtype',
                  invtrans.VATRate AS 'invtrans VATRate',
                  invtrans.SiteName AS 'invtrans SiteName',
                  invtrans.SiteTown AS 'invtrans SiteTown',
                  invtrans.UnitPrice AS 'invtrans UnitPrice',
                  invtrans.Type AS 'invtrans Type',
                  invtrans.InvBatch AS 'invtrans InvBatch',
                  invoiceheaders.Name AS 'invoiceheaders Name',
                  invoiceheaders.Addr1 AS 'invoiceheaders Addr1',
                  invoiceheaders.Addr2 AS 'invoiceheaders Addr2',
                  invoiceheaders.Addr3 AS 'invoiceheaders Addr3',
                  invoiceheaders.Town AS 'invoiceheaders Town',
                  invoiceheaders.County AS 'invoiceheaders County',
                  invoiceheaders.Country AS 'invoiceheaders Country',
                  invoiceheaders.PostCode AS 'invoiceheaders PostCode',
                  invoiceheaders.EMail AS 'invoiceheaders EMail',
                  invoiceheaders.Fax AS 'invoiceheaders Fax',
                  invoiceheaders.InvNo AS 'invoiceheaders InvNo',
                  invoiceheaders.InvDate AS 'invoiceheaders InvDate',
                  invoiceheaders.InvType AS 'invoiceheaders InvType',
                  invoiceheaders.DelType AS 'invoiceheaders DelType'
FROM (invtrans invtrans
     INNER JOIN invoiceheaders invoiceheaders ON (invoiceheaders.InvNo = invtrans.InvNumber ))
WHERE
(
  invtrans.InvBatch = "."'".$batch1."'"." OR invtrans.InvBatch = "."'".$batch2."'"." )
ORDER BY  invoiceheaders.InvNo

";

$result = mysql_query($query) or die(mysql_error());

//Create Headers

    echo "Customer Ref";
    echo chr(9);
    echo "Account Ref";
    echo chr(9);
    echo "TxnDate";
    echo chr(9);
    echo "Invoice No";
    echo chr(9);
    echo "BillingAddress1";
    echo chr(9);
    echo "BillingAddress2";
    echo chr(9);
    echo "BillingAddress3";
    echo chr(9);
    echo "BillingAddressTown";
    echo chr(9);
    echo "BillingAddressCounty";
    echo chr(9);
    echo "BillingAddressCountry";
    echo chr(9);
    echo "BillingAddressPostcode";
    echo chr(9);
    echo "Phone";
    echo chr(9);
    echo "Fax";
    echo chr(9);
    echo "email";
    echo chr(9);
    echo "Description";
    echo chr(9);
    echo "Rate";
    echo chr(9);
    echo "UnitOfMeasure";
    echo chr(9);
    echo "SalesTaxCode";
    echo chr(9);
    echo "Amount";
    echo chr(9);
    echo chr(13);

while($row = mysql_fetch_array($result))

  {
    //create variables
    $description = $row['invtrans StdInvNar1']." ".$row['invtrans StdInvNar2']." ".$row['invtrans StdInvNar3']." ".$row['invtrans StdInvNar4']." ".$row['invtrans StdInvNar5']." ".$row['invtrans StdInvNar6']." ".$row['invtrans StdInvNar7']." ".$row['invtrans StdInvNar8']." ".$row['invtrans StdInvNar9']." ".$row['invtrans StdInvNar10'];
    $description = $description." ".$row['invtrans InvNar1']." ".$row['invtrans InvNar2']." ".$row['invtrans InvNar3']." ".$row['invtrans InvNar4']." ".$row['invtrans InvNar5']." ".$row['invtrans InvNar6']." ".$row['invtrans InvNar7']." ".$row['invtrans InvNar8']." ".$row['invtrans InvNar9']." ".$row['invtrans InvNar10'];


    //output file
    echo $row['invoiceheaders Name'];
    echo chr(9);
    echo "Account Ref";
    echo chr(9);
    echo $row['invoiceheaders InvDate'];
    echo chr(9);
    echo $row['invoiceheaders InvNo'];
    echo chr(9);
    echo $row['invoiceheaders Addr1'];
    echo chr(9);
    echo $row['invoiceheaders Addr2'];
    echo chr(9);
    echo $row['invoiceheaders Addr3'];
    echo chr(9);
    echo $row['invoiceheaders Town'];
    echo chr(9);
    echo $row['invoiceheaders County'];
    echo chr(9);
    echo $row['invoiceheaders Country'];
    echo chr(9);
    echo $row['invoiceheaders PostCode'];
    echo chr(9);
    echo "01212331234";
    echo chr(9);
    echo $row['invoiceheaders Fax'];
    echo chr(9);
    echo $row['invoiceheaders EMail'];
    echo chr(9);
    echo $description;
    echo chr(9);
    echo $row['invtrans Charge'];
    echo chr(9);
    echo "UnitOfMeasure";
    echo chr(9);
    echo "SalesTaxCode";
    echo chr(9);
    echo $row['invtrans Charge'];
    echo chr(9);
    echo chr(13);
  }

?>