hi there
i am trying to export data from my sugar db to csv. i got this code working, but do not know how to
do the following.
Put a timestamp in front of the file name
save the csv in spesific folder
in my phone mobile it cuts of the leading zero.
Please help
code begins
<?php
$host = '209.203.46.123';
$user = 'paul';
$pass = '********';
$db = '******';
$table = 'Inter_Active_campaign_targets';
$file = 'Leads';
$link = mysql_connect($host, $user, $pass) or die("Can not connect." . mysql_error());
mysql_select_db($db) or die("Can not connect.");
$result = mysql_query("SHOW COLUMNS FROM ".$table."");
$i = 0;
if (mysql_num_rows($result) > 0) {
while ($row = mysql_fetch_assoc($result)) {
$csv_output .= $row['Field'].", ";
$i++;
}
}
$csv_output .= "\n";
$values = mysql_query("SELECT * FROM ".$table."");
while ($rowr = mysql_fetch_row($values)) {
for ($j=0;$j<$i;$j++) {
$csv_output .= $rowr[$j].", ";
}
$csv_output .= "\n";
}
$filename = $file."_".date("Y-m-d_H-i",time());
header("Content-type: application/vnd.ms-excel");
header("Content-disposition: csv" . date("Y-m-d") . ".csv");
header( "Content-disposition: filename=".$filename.".csv");
print $csv_output;
exit;
?>


LinkBack URL
About LinkBacks



Reply With Quote
Bookmarks