php导出数据到csv文件实例代码如下:
<?php
include ("../admin/inc/inc.php");
$times = time();
$filename = $times . ".csv";
$a = "联系人,联系电话,小区,所需材料,备注,申请时间 ";
$days = postget("days");
$mktime = daystomktime($days);
$sql = "select * from tugou where ($times-times)<$mktime";
$db = new db();
$result = $db->query($sql);
$rs = $db->fetch($result, 0);
foreach ($rs as $v => $vv) {
$a.= $vv['name'] . ',' . $vv['mo'] . "," . $vv['comm'] . "," . commbox($vv['cbox']) . ",";
$a.= "" . $vv['bak'] . "," . date('y-m-d', $vv['times']) . "
";
}
//echo $a;
$hod = fopen($filename, "w+");
if (fwrite($hod, $a)) {
echo "生成文件成功,点击<a href=$filename target=_blank>下载excel
文档</a>";
}
function daystomktime($days) {
switch ($days) {
case 1:
$t = 86400;
break;
case 7:
$t = 86400 * 7;
break;
case 30:
$t = 86400 * 30;
break;
case 90:
$t = 86400 * 90;
break;
case 2048:
$t = 86400 * 2048;
break;
}
return $t;
}
function commbox($ars) {
if (trim($ars) == '') {
return ' ';
}
$array = include ("tugou.php");
$tmp = explode(',', $ars);
$str = '';
if ($tmp) {
foreach ($tmp as $c) {
$str.= $array[intval($c) ] . '|';
}
}
return $str;
}
?>数据库的结构代码如下:
create table if not exists `tugou` ( `id` int(8) not null auto_increment, `name` varchar(20) default null comment '名字', `mo` varchar(20) default null comment '手机', `comm` varchar(100) default null, `bak` varchar(500) default null comment '备份', `cbox` varchar(500) default null comment '类型', `times` int(4) default null, `ip` varchar(20) default null,//开源代码phprm.com primary key (`id`) ) engine=innodb default charset=utf8 auto_increment=8 ;
wordpress外贸网站astra整站源码,一套模板,多种首页风格。 安装: 第一:上传网站程序到你的空间。 第二:数据库操作,用phpmyadmin 导入根目录下的 sql文件 到网站所使用的数据库里。 第三:编辑wp-config.php :define('WP_HOME','http://www.test.com');define('WP_SITEURL',
0
立即学习“PHP免费学习笔记(深入)”;
本文地址:
转载随意,但请附上文章地址:-)
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号