Home  >  Article  >  Backend Development  >  Convert mysql data table to excel file format using PHP_PHP tutorial

Convert mysql data table to excel file format using PHP_PHP tutorial

WBOY
WBOYOriginal
2016-07-20 11:05:08840browse

Author: mydowns Source: Seize the time website: http://www.85time.com, http://www.mydowns.com
The original post address is as follows:
http://www.mydowns.com/article_show .php?id=32
The details are as follows: 🎜>$DB_DBName = "mydowns";
$DB_TBLName = "user";
$Connect = @mysql_connect($DB_Server, $DB_Username, $DB_Password)
or die("Couldn't connect." );
$Db = @mysql_select_db($DB_DBName, $Connect)
or die("Couldn't select database.");
$file_type = "vnd.ms-excel";
$file_ending = "xls";
header("Content-Type: application/$file_type");
header("Content-Disposition: attachment; filename=mydowns.$file_ending");
header( "Pragma: no-cache");
header("Expires: 0");
$now_date = date('Y-m-d H:i');
$title = "Database name:$DB_DBName, Data table: $DB_TBLName, backup date: $now_date";
$sql = "Select * from $DB_TBLName";
$ALT_Db = @mysql_select_db($DB_DBName, $Connect)
or die("Couldn 't select database");
$result = @mysql_query($sql,$Connect)
or die(mysql_error());
echo("$title");
$sep = " ";
for ($i = 0; $i < mysql_num_fields($result); $i++) {
echo mysql_field_name($result,$i) . " ";
}
print("");
$i = 0;
while($row = mysql_fetch_row($result))
{
$schema_insert = "";
for($j=0 ; $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 .= " ";
print(trim($schema_insert));
print "";
$i++;
}
return (true);
?>





http://www.bkjia.com/PHPjc/445165.html

www.bkjia.com

truehttp: //www.bkjia.com/PHPjc/445165.htmlTechArticleAuthor: mydowns Source: Seize the time website: http://www.85time.com, http://www .mydowns.com The original post address is as follows: http://www.mydowns.com/article_show.php?id=32 The details are as follows: ?php $DB...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn