Home > Backend Development > PHP Tutorial > php使用header导出excel时会少第一行

php使用header导出excel时会少第一行

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-23 13:59:07
Original
1336 people have browsed it

http://192.168.0.200/test/khall.php?mindate=2014-04-01&maxdate=2014-04-30&keys=
Copy after login


<?php    header("Content-type:application/vnd.ms-excel");    header("Content-Disposition:attachement;filename=".$_GET['keys']."".date("Ymd").".xls");    echo iconv('utf-8', 'gbk', "时间\t类型\t区域\t姓名\t具体地址\t联系电话\t证件号\t套餐\t时长\t赠送\t金额\t经办人\t帐号\t备注\n");      include("db.php");            date_default_timezone_set("PRC");            $mindate=$_GET['mindate'];            $maxdate=$_GET['maxdate'];            $dates="dates>='".$mindate."' and dates<='".$maxdate."'";        if (!empty($_GET['keys'])) {            $keys=$_GET['keys'];            $ww="(`area` like '%".$keys."%' or `type` like '%".$keys."%' or `names` like '%".$keys."%' or `add` like '%".$keys."%' or `dur` like '%".$keys."%')";            $wh="where {$ww} and {$dates}";  }           else{$wh="where {$dates}";}            $sql="SELECT * FROM `khxx` {$wh}";           // echo "$sql";            mysql_query('set names gbk');            $query=mysql_query($sql);            $rs=mysql_fetch_array($query);            while ($rs=mysql_fetch_array($query)){            echo "{$rs['dates']}\t{$rs['type']}\t{$rs['area']}\t{$rs['names']}\t{$rs['add']}\t{$rs['phone']}\t{$rs['no']}\t{$rs['set']}\t{$rs['dur']}\t{$rs['give']}\t{$rs['moneys']}\t{$rs['attn']}\t{$rs['username']}\t{$rs['rem']}\n";            }?>
Copy after login

使用echo 输入sql语句是正常的
SELECT * FROM `khxx` where dates>='2014-04-01' and dates<='2014-04-30'
Copy after login

可生成时就是少了第一条数据


回复讨论(解决方案)

还有就是使用了mysql_query('set names gbk');
但是上个页面会传递$key变量值 因为传递来的值是utf-8的 在执行sql语句时就会失效

            $rs=mysql_fetch_array($query); //你这里多读了一行
            while ($rs=mysql_fetch_array($query)){

$keys=$_GET['keys'];
改为
$keys = iconv('utf-8', 'gbk', $_GET['keys']);

还有就是使用了mysql_query('set names gbk');
但是上个页面会传递$key变量值 因为传递来的值是utf-8的 在执行sql语句时就会失效
%".$keys."% 改为%". iconv('utf-8', 'gbk', '$keys')."%

$keys=$_GET['keys'];
改为
$keys = iconv('utf-8', 'gbk', $_GET['keys']);
今天少了你的提点可怎么办呀

认识了规律就好了

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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template