php+mysql导出CSV数据文件
2009-03-31 09:18
1016 查看
请求export_csv.php时如果合法用户就会弹出下面这样的保存下载框:
代码如下:
<?php
require_once('main.php');
if($_COOKIE['CRM_UID'] == null){
showmessage("非法用户!","login.php",1250,'icon_error.jpg');
}
if($_COOKIE['CRM_TYPE'] == 4){
showmessage( "您没有权限!", 'index.php?file=online', 1250, 'icon_error.jpg');
}
$type = $_GET['t'];
export_csv($type);
/**
*导出到CSV文件
* @param <type> $type
*/
function export_csv($type)
{
$filename = date('YmdHis').".csv";
header("Content-type:text/csv");
header("Content-Disposition:attachment;filename=".$filename);
header('Cache-Control:must-revalidate,post-check=0,pre-check=0');
header('Expires:0');
header('Pragma:public');
echo array_to_string(get_export_data($type));
}
/**
*导出数据转换
* @param <type> $result
*/
function array_to_string($result)
{
if(empty($result)){
return i("没有符合您要求的数据!^_^");
}
$data;
$size_result = sizeof($result);
for($i = 0 ; $i < $size_result ; ++ $i) {
$data .= i($result[$i]['orderID']).','.i($result[$i]['username'])."\n";
}
return $data;
}
/**
*获取导出报表的数据
* @param <type> $condition
* @return <type>
*/
function get_export_data($condition)
{
$where = " state = 0 ";
switch($condition)
{
case 'week':
$where .= " and week(date) = week(current_date()-1 ) ;";//每周从周一开始
break;
case 'month':
$where .= " and month(date) = month(current_date()) ;";
break;
case 'year':
$where .= " and year(date) = year(current_date()) ;";
break;
default:
break;
}
$sql = " select * from net_order_detail where {$where}";
$db = get_db();
$res = $db->get_results($sql,ARRAY_A);
return $res;
}
/**
*编码转换
* @param <type> $strInput
* @return <type>
*/
function i($strInput)
{
return iconv('utf-8','gb2312',$strInput);
}
?>
代码如下:
<?php
require_once('main.php');
if($_COOKIE['CRM_UID'] == null){
showmessage("非法用户!","login.php",1250,'icon_error.jpg');
}
if($_COOKIE['CRM_TYPE'] == 4){
showmessage( "您没有权限!", 'index.php?file=online', 1250, 'icon_error.jpg');
}
$type = $_GET['t'];
export_csv($type);
/**
*导出到CSV文件
* @param <type> $type
*/
function export_csv($type)
{
$filename = date('YmdHis').".csv";
header("Content-type:text/csv");
header("Content-Disposition:attachment;filename=".$filename);
header('Cache-Control:must-revalidate,post-check=0,pre-check=0');
header('Expires:0');
header('Pragma:public');
echo array_to_string(get_export_data($type));
}
/**
*导出数据转换
* @param <type> $result
*/
function array_to_string($result)
{
if(empty($result)){
return i("没有符合您要求的数据!^_^");
}
$data;
$size_result = sizeof($result);
for($i = 0 ; $i < $size_result ; ++ $i) {
$data .= i($result[$i]['orderID']).','.i($result[$i]['username'])."\n";
}
return $data;
}
/**
*获取导出报表的数据
* @param <type> $condition
* @return <type>
*/
function get_export_data($condition)
{
$where = " state = 0 ";
switch($condition)
{
case 'week':
$where .= " and week(date) = week(current_date()-1 ) ;";//每周从周一开始
break;
case 'month':
$where .= " and month(date) = month(current_date()) ;";
break;
case 'year':
$where .= " and year(date) = year(current_date()) ;";
break;
default:
break;
}
$sql = " select * from net_order_detail where {$where}";
$db = get_db();
$res = $db->get_results($sql,ARRAY_A);
return $res;
}
/**
*编码转换
* @param <type> $strInput
* @return <type>
*/
function i($strInput)
{
return iconv('utf-8','gb2312',$strInput);
}
?>
相关文章推荐
- PHP导出MySQL数据到Excel或者CSV文件
- 用php导入10W条+ 级别的csv大文件数据到mysql。导出10W+级别数据到csv文件
- 用php导入10W条+ 级别的csv大文件数据到mysql。导出10W+级别数据到csv文件
- php使用指定编码导出mysql数据到csv文件的方法
- PHPExcel使用-使用PHPExcel导出文件-导出MySQL数据
- php导出csv数据在浏览器中输出提供下载或保存到文件的示例
- php 导出大数据到csv文件
- PHP如何查询MySQL数据页面并输出内容到页面,并另存为CSV或EXCEL文件
- mysql 导出数据到csv文件的命令
- PHP 将MySQL数据导出csv
- php数据导入导出之excel(csv文件)
- mysql 导出数据到csv文件的命令
- php导出大数据保存到csv文件
- PHP导出MySQL数据到Excel文件(fputcsv)
- mysql 导出数据到csv文件的命令
- mysql 导入导出csv文件数据语法
- php导出csv数据在浏览器中输出提供下载或保存到文件的示例
- php读取含有3w条以上数据的csv文件,并选择性将相应字段的数据导入至mysql
- mysql 查询数据 导出 .csv文件
- php数据导入导出之excel(csv文件)