hisham
IS-IT--Management
- Nov 6, 2000
- 194
I use the following code to Dump For Table in xls format:
----------------------------------------------------------------
$sql = "Select name, date from my_table";
$result = @mysql_query($sql)
or die("Couldn't execute query:<br>" . mysql_error(). "<br>" . mysql_errno());
$file_type = "vnd.ms-excel";
$file_ending = "xls";
header("Content-Type: application/$file_type"
header("Content-Disposition: attachment; filename=Excel_ my_table.$file_ending"
header("Pragma: no-cache"
header("Expires: 0"
$sep = "\t";
for ($i = 0; $i < mysql_num_fields($result); $i++) {
echo mysql_field_name($result,$i) . "\t";
}
print("\n"
while($row = mysql_fetch_row($result)){
$schema_insert = "";
for($j=0; $j<mysql_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";
}
?>
----------------------------------------------------------
in my_table I have the field “date” its type is timestamp(14) if I have an entry in this field i.e. 20021114014611 , the result for this entry in the Excel file will display without formatting. Any help please?
Thanks in advance.
----------------------------------------------------------------
$sql = "Select name, date from my_table";
$result = @mysql_query($sql)
or die("Couldn't execute query:<br>" . mysql_error(). "<br>" . mysql_errno());
$file_type = "vnd.ms-excel";
$file_ending = "xls";
header("Content-Type: application/$file_type"
header("Content-Disposition: attachment; filename=Excel_ my_table.$file_ending"
header("Pragma: no-cache"
header("Expires: 0"
$sep = "\t";
for ($i = 0; $i < mysql_num_fields($result); $i++) {
echo mysql_field_name($result,$i) . "\t";
}
print("\n"
while($row = mysql_fetch_row($result)){
$schema_insert = "";
for($j=0; $j<mysql_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";
}
?>
----------------------------------------------------------
in my_table I have the field “date” its type is timestamp(14) if I have an entry in this field i.e. 20021114014611 , the result for this entry in the Excel file will display without formatting. Any help please?
Thanks in advance.