Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

This code generate Dump For Table but without date formate !!

Status
Not open for further replies.

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(&quot;Couldn't execute query:<br>&quot; . mysql_error(). &quot;<br>&quot; . mysql_errno());

$file_type = &quot;vnd.ms-excel&quot;;
$file_ending = &quot;xls&quot;;

header(&quot;Content-Type: application/$file_type&quot;);
header(&quot;Content-Disposition: attachment; filename=Excel_ my_table.$file_ending&quot;);
header(&quot;Pragma: no-cache&quot;);
header(&quot;Expires: 0&quot;);

$sep = &quot;\t&quot;;

for ($i = 0; $i < mysql_num_fields($result); $i++) {
echo mysql_field_name($result,$i) . &quot;\t&quot;;
}
print(&quot;\n&quot;);

while($row = mysql_fetch_row($result)){
$schema_insert = &quot;&quot;;
for($j=0; $j<mysql_num_fields($result);$j++)
{
if(!isset($row[$j]))
$schema_insert .= &quot;NULL&quot;.$sep;
elseif ($row[$j] != &quot;&quot;)
$schema_insert .= &quot;$row[$j]&quot;.$sep;
else
$schema_insert .= &quot;&quot;.$sep;
}
$schema_insert = str_replace($sep.&quot;$&quot;, &quot;&quot;, $schema_insert);
$schema_insert = preg_replace(&quot;/\r\n|\n\r|\n|\r/&quot;, &quot; &quot;, $schema_insert);
$schema_insert .= &quot;\t&quot;;
print(trim($schema_insert));
print &quot;\n&quot;;
}
?>
----------------------------------------------------------
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.
 
Format it as a date in your code. Excell is probably expecting dates to have separators between years and months, etc.

You'll also get the best results if you rearrange the fields of your date to match what Excel expects. For example, format &quot;20021114014611&quot; &quot;11/14/2002 01:45:11&quot; in the United States. ______________________________________________________________________
TANSTAAFL!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top