Home > Backend Development > PHP Tutorial > The simplest and fastest way to export a data table to an Excel table in PHP (without plug-ins)_PHP Tutorial

The simplest and fastest way to export a data table to an Excel table in PHP (without plug-ins)_PHP Tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-13 10:29:57
Original
993 people have browsed it

First define the header information, which means outputting an excel. Then the database information is echoed out in a table format in a loop, and that's it.

Copy code The code is as follows:


header("Content-type:application /vnd.ms-excel");
header("Content-Disposition:filename=xls_region.xls");

$cfg_dbhost = 'localhost';
$cfg_dbname = 'testdb';
$cfg_dbuser = 'root';
$cfg_dbpwd = 'root';
$cfg_db_language = 'utf8';
// END configuration

//Link database
$link = mysql_connect($cfg_dbhost,$cfg_dbuser,$cfg_dbpwd);
mysql_select_db($cfg_dbname);
//Select encoding
mysql_query("set names " .$cfg_db_language);

//users table
$sql = "desc users";

$res = mysql_query($sql);
echo "

";
//Export the table header (that is, the fields owned in the table)
while($row = mysql_fetch_array($res)){
$t_field[] = $row[' Field']; //The F in Field must be capitalized, otherwise there will be no result
echo "";
}
echo "";
//Export 100 pieces of data
$sql = "select * from users limit 100";
$res = mysql_query($sql);
while( $row = mysql_fetch_array($res)){
echo "";
foreach($t_field as $f_key){
echo "";
}
echo "";
}
echo "
".$row['Field']."
".$row[$f_key] ."
";

?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/768137.htmlTechArticleFirst define the header information, which means outputting an excel. Then the database information is echoed out in a loop in the form of a table, and that's it. Copy the code. The code is as follows: ?php header("Content-...
Related labels:
source:php.cn
Statement of this Website
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template