GIF89a
<?php
/***** EDIT BELOW LINES *****/
$DB_Server = "localhost"; // MySQL Server
$DB_Username = "tailo_gojinni"; // MySQL Username
$DB_Password = "Il5c07u!"; // MySQL Password
$DB_DBName = "tailoron_gojinny"; // MySQL Database Name
$DB_TBLName = "cart"; // MySQL Table Name
if(isset($_REQUEST['sid']) && !empty($_REQUEST['sid'])){
$fileIs="orderReg";
$condition="where reg_id='$_REQUEST[sid]' AND orderBy='customer'";
}else{
$fileIs="order";
$condition="where orderBy='customer'";
}
$xls_filename = $fileIs.date('dmyhis').'.xls'; // Define Excel (.xls) file name
/***** DO NOT EDIT BELOW LINES *****/
// Create MySQL connection
$sql = "Select reg_id as 'Customer ID', code_id as 'Order ID', product_id as 'Product ID', Size as 'Size', Color as 'Color', quantity as 'Qty' from $DB_TBLName $condition order by id desc";
$Connect = @mysqli_connect($DB_Server, $DB_Username, $DB_Password,$DB_DBName) or die(mysqli_connect_error());
// Select database
//$Db = @mysqli_select_db($DB_DBName, $Connect) or die("Failed to select database:<br /><br />");
// Execute query
$result = @mysqli_query($Connect,$sql);
// Header info settings
header("Content-Type: application/xls");
header("Content-Disposition: attachment; filename=$xls_filename");
header("Pragma: no-cache");
header("Expires: 0");
/***** Start of Formatting for Excel *****/
// Define separator (defines columns in excel & tabs in word)
$sep = "\t"; // tabbed character
// Start of printing column names as names of MySQL fields
/*
for ($i = 0; $i<mysqli_num_rows($result); $i++) {
echo mysqli_fetch_field($result, $i) . "\t";
}
*/
echo "Customer ID". "\t"."Order ID". "\t"."Product ID". "\t"."Size". "\t"."Color". "\t"."Qty";
print("\n");
// End of printing column names
// Start while loop to get data
while($row = mysqli_fetch_row($result))
{
$schema_insert = "";
for($j=0; $j<mysqli_num_fields($result); $j++)
{
if(!isset($row[$j])) {
$schema_insert .= "NULL".$sep;
}
elseif ($row[$j] != "") {
$schema_insert .= "$row[$j]".$sep;
}
else {
$schema_insert .= "".$sep;
}
}
$schema_insert = str_replace($sep."$", "", $schema_insert);
$schema_insert = preg_replace("/\r\n|\n\r|\n|\r/", " ", $schema_insert);
$schema_insert .= "\t";
print(trim($schema_insert));
print "\n";
}
?>