PHP-Code:
<?php
$DatabaseHost = "server";
$DatabaseUser = "benutzer";
$DatabasePassword = "passwort";
$Database = "datenbank";
$Table = "jos_vm_orders";
$Table2 = "jos_users";
$Table3 = "jos_vm_order_item";
$Table4 = "jos_vm_user_info";
header('Content-Type: text/x-csv');
header('Expires: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Content-Disposition: attachment; filename=bestellungen_datumsbereich.csv');
header('Pragma: no-cache');
$DatabasePointer = mysql_connect($DatabaseHost, $DatabaseUser, $DatabasePassword);
mysql_select_db($Database, $DatabasePointer);
#Eingabe in UNIX timestamp umwandeln
$begriff = mysql_real_escape_string($_POST['searchterm']);
$ResultPointer = mysql_query("SELECT v.user_id, v.first_name, v.last_name, v.phone_1, v.fax, v.address_1, v.city, v.country, v.zip, v.user_email, v.vm_inhaber, o.order_id, x.order_id, x.order_item_name, x.product_quantity, x.product_attribute, o.order_total, o.cdate, o.user_id, u.id, u.name FROM $Table o, $Table2 u, $Table3 x, $Table4 v where o.user_id=u.id AND x.order_id=o.order_id AND u.id=v.user_id AND o.cdate like '%$begriff%'");
for($i = 0, $Export = ""; $i < mysql_num_rows($ResultPointer); $i++)
{
$Daten = mysql_fetch_object($ResultPointer);
$Spalte[] = str_replace("\"", "\"\"", $Daten->name);
$Spalte[] = str_replace("\"", "\"\"", money_format('%i',$Daten->order_total));
$Spalte[] = str_replace("\"", "\"\"", date("d-m-Y H:i:s",$Daten->cdate));
$Spalte[] = str_replace("\"", "\"\"", $Daten->order_item_name);
$Spalte[] = str_replace("\"", "\"\"", $Daten->product_attribute);
$Spalte[] = str_replace("\"", "\"\"", $Daten->product_quantity);
$Spalte[] = str_replace("\"", "\"\"", $Daten->vm_inhaber);
$Spalte[] = str_replace("\"", "\"\"", $Daten->first_name);
$Spalte[] = str_replace("\"", "\"\"", $Daten->last_name);
$Spalte[] = str_replace("\"", "\"\"", $Daten->address_1);
$Spalte[] = str_replace("\"", "\"\"", $Daten->zip);
$Spalte[] = str_replace("\"", "\"\"", $Daten->city);
$Spalte[] = str_replace("\"", "\"\"", $Daten->country);
$Spalte[] = str_replace("\"", "\"\"", $Daten->phone_1);
$Spalte[] = str_replace("\"", "\"\"", $Daten->fax);
$Spalte[] = str_replace("\"", "\"\"", $Daten->user_email);
for($j = 0; $j < count($Spalte); $j++)
{
$Export .= "\"" . $Spalte[$j] . "\"";
if($j != count($Spalte)-1)
{
$Export .= ";";
}
}
$Export .= "\r\n";
$Spalte = "";
}
mysql_close($verbindung);
echo$Export;
?>
Lesezeichen