php数据库读取到表格 php数据库读取到表格的方法

php如何把mysql数据库导入到excel表格

?php

成都创新互联公司-成都网站建设公司,专注网站制作、成都网站建设、网站营销推广,主机域名,网络空间,网站托管有关企业网站制作方案、改版、费用等问题,请联系成都创新互联公司

//需求:用php将mysql数据导入到excel中

//数据库配置信息

$DB_Server = "localhost";

$DB_Username = "root";

$DB_Password = "admin";

$DB_DBName = "shop";

$DB_TBLName = "sdb_widgets_set";

$savename = date("Y-m-j H:i:s");

// 数据库连接

$Connect = @mysql_connect($DB_Server, $DB_Username, $DB_Password) or die("Couldn't connect.");

//注意mysql 导入cxcel中的时候

mysql_query("Set Names 'gbk'");

//定义文件导出的格式

$file_type = "vnd.ms-excel";

//定义文件后缀名称

$file_ending = "xls";

header("Content-Type: application/$file_type;charset=gbk");

header("Content-Disposition: attachment; filename=".$savename.".$file_ending");

//header("Pragma: no-cache");

$now_date = date("Y-m-j H:i:s");

//定义要输出的数据表标题

$title = "数据表名:$DB_TBLName, | 日期:$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/n");

//定义制表格符号

$sep = "/t";

//逐个取出数据表字段

for ($i = 0; $i mysql_num_fields($result); $i++) {

echo mysql_field_name($result,$i) . "/t";

}

print("/n");

// $i = 0;

//循环打印出数据表中的数据

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;

else if ($row[$j] != "")

$schema_insert .= "$row[$j]".$sep;

else

$schema_insert .= "".$sep;

}

$schema_insert = str_replace($sep."$", "", $schema_insert);

$schema_insert .= "/t";

print(trim($schema_insert));

print "/n";

// $i++;

}

return (true);

?

请教:php读取数据库成表格分列

与SQL无关,怎么ORDER BY都没关系,下面的语句都是适用的:

$i=0;//已经输出的数据个数

echo 'table';

while($title =mysql_fetch_row($titles))

{

//第一个地方………………下面的4表示每行显示四个

if ($i % 4==0) echo 'tr';

$ddd=$title[2];

//第二个地方………………

$i++;

echo "td a href=\"$title[1]\" target=\"_blank\"$ddd/a/td";

//这里无需处理……………………

}

php 把数据库中的数据 输出到 Excel

方法一:

?php

header("Content-type:application/vnd.ms-excel");

header("Content-Disposition:attachment;filename=test_data.xls");

$tx='表头';

echo

$tx."\n\n";

//输出内容如下:

echo

"姓名"."\t";

echo

"年龄"."\t";

echo

"学历"."\t";

echo

"\n";

echo

"张三"."\t";

echo

"25"."\t";

echo

"本科"."\t";

?

方法二:

PHPEXCEL

类库,功能强大,支持win

Excel2003

,Win

Excel2007.下载类库,里边有例子

网站标题:php数据库读取到表格 php数据库读取到表格的方法
分享链接:https://www.cdcxhl.com/article38/dogdcsp.html

成都网站建设公司_创新互联,为您提供网站设计外贸建站定制开发做网站软件开发App设计

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

手机网站建设