您的位置:首页 > 编程语言 > PHP开发

tp-导出

2015-09-25 11:56 561 查看

导出订单

这是参照网上的一个例子写的导出,其实还是觉得不是很完善的,感觉有点乱七八糟的,是一个很讨厌的同事帮忙写的。

先上张图的哈。



view 代码

//HTML 代码
其实就是form的表单提交罢了。


controller层。

忽略其他的会员信息表之类的。最主要的是会员表主表跟附属表。联查,写在一起。得出的excel文件的模板,如图:



代码:

public function isExp_rdot(){
if(IS_POST){
$temp = array(
'id'=>'id',
'tradeno'=>'订单号',
'pnum'=>'数量',
'pname'=>'产品名'
);
/*先把外面的view层展示的可以到处的数据查出来
其实还是有一些其他的条件的,比如说加些时间的限制什么的
*/
$orderExt = M('order')->field('wjz_order.id,wjz_order.tradeno,wjz_order_ext.pnum,wjz_order_ext.pname')
->join('LEFT JOIN wjz_order_ext ON wjz_order_ext.oid = wjz_order.id')
->where('1=1')
->select();

/*以下是浏览器自带的输出excel格式的代码*/
header("Content-type:application/octet-stream");
header("Accept-Ranges:bytes");
header("Content-type:application/vnd.ms-excel");
header("Content-Disposition:attachment;filename=".$sup_info['true_name'].date("Y-m-d").".xls");
header("Pragma: no-cache");
header("Expires: 0");

if($orderExt){
/*匹配出用户需要的数据头是哪几个*/
$header = null;
if(I("post.isP")){
foreach(I("post.isP") as $key=>$val){
if(count(I("post.isP")) == $key+1){
$header .= $temp[$val]."\n";
}else{
$header .= $temp[$val]."\t";
}
}
}
echo $header;

/*输出相对应的数据*/
foreach($orderExt as $key=>$val){
/*M("order")->where(array('id'=>$val['oid']))->setInc('is_expoxt_num');/*做数据库导出次数操作*/
$data_order = null;
foreach(I("post.isP") as $key => $row){
if(count(I("post.isP")) == $key+1){
$data_order .= $val[$row]."\n";
}else{
$data_order .=$val[$row]."\t";
}
}
echo $data_order;
}
}else{
exit("暂无您所查询的数据");
}
}else{
exit("参数错误");
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: