Forum Moderators: coopster
header("Content-type: application/vnd.ms-excel");
header("Content-disposition: attachment; filename=usps_export.csv");
Any Suggestions?
Thank you in advance
echo "Full Name,Address,City,State,Zip Code,Country,E Mail,Reference Number\n";
Than I run the sql to grab the data, but the file output is four blank lines the header and than the data. I would think if the loop was the issue, the header would be line 1 and the data would start on line 6.
Make sense?
echo "Full Name,Address,City,State,Zip Code,Country,E Mail,Reference Number\n";
$sqla="SELECT * FROM orders where order_status!='COMPLETE' and shipping_type='Priority' or order_status!='COMPLETE' and shipping_type='Express'";
#echo "<br>SQLA: $sqla<br>";
$resulta = mysql_query($sqla) or die('Query failed: ' . mysql_error());
$numresa=mysql_num_rows($resulta);
while ($linea = mysql_fetch_array($resulta, MYSQL_ASSOC)) {
$orderid=$linea["orderid"];
$customerid=$linea["customerid"];
$shipping_type=$linea["shipping_type"];
$sqlc="SELECT * FROM customers WHERE customerid='$customerid'";
#echo "SQLC: $sqlc<br>";
$resultc = mysql_query($sqlc) or die('Query failed: ' . mysql_error());
$numresc=mysql_num_rows($resultc);
while ($linec = mysql_fetch_array($resultc, MYSQL_ASSOC)) {
$name=$linec["name"];
$email=$linec["email"];
$address=$linec["address"];
$city=$linec["city"];
$state=$linec["state"];
$zip=$linec["zip"];
$country=$linec["country"];
$nametoship=$linec["nametoship"];
$addresstoship=$linec["addresstoship"];
$citytoship=$linec["citytoship"];
$statetoship=$linec["statetoship"];
$ziptoship=$linec["ziptoship"];
$countrytoship=$linec["countrytoship"];
echo "$nametoship,$addresstoship,$citytoship,$statetoship,$ziptoship,$countrytoship,$email,$orderid\n";
}
}
Example file:
-- php file start ---
<?php
echo "123";
?>
-- php file end ---
Would output everything before the <?php tag, i.e. 2 lines.
Files like this may also cause troubles:
-- php file start ---
<?php
some php code here, for example database processing
?>
<?php
some more code here, for example CSV output
?>
-- php file end ---
This code is above the first sql:
Full Name,Address,City,State,Zip Code,Country,E Mail,Reference Number
<?php
header("Content-type: application/vnd.ms-excel");
header("Content-disposition: attachment; filename=usps_export.csv");
require_once("functions/page_functions.php");
Can you try this SQL from command line or MyAdmin and see if you get any rows returned where all the values are null or empty strings. It could be that the DB has empty rows? It is something to check.
SELECT * FROM customers
SELECT * FROM orders where order_status!='COMPLETE' and shipping_type='Priority' or order_status!='COMPLETE' and shipping_type='Express'
Is it possible that some of the text fields have some bad chars in them.. like tab chars or newline chars... a lot of the time if you are outputting the sql to a command line or using an admin tool it will parse those out and you won't see them until they mess up code.... could have happened while remapping things over to your new server.
Are you able to check for such a thing? I am just throwing out ideas here...
[edited by: Demaestro at 3:31 pm (utc) on Sep. 27, 2007]
Also make sure that <?php or javascript stuff is at the very top of the page with no white spaces before them.
Hope that helps