When php uses the header to export an excel file, the first line is missing.

Source: Internet
Author: User
When php uses the header to export an excel file, the first line is missing.
http://192.168.0.200/test/khall.php?mindate=2014-04-01&maxdate=2014-04-30&keys=


 = '". $ Mindate."' and dates <= '". $ maxdate."' "; if (! Empty ($ _ GET ['Keys ']) {$ keys = $ _ GET ['Keys']; $ ww = "('region' 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 ['region']} \ 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 ";} ?>

It is normal to input SQL statements using echo.
SELECT * FROM `khxx` where dates>='2014-04-01' and dates<='2014-04-30'

The first data entry is missing when it is generated.


Reply to discussion (solution)

Also, mysql_query ('set names gbk') is used ');
However, the $ key variable value will be passed on the previous page because the passed value is UTF-8 and will become invalid when the SQL statement is executed.

$ Rs = mysql_fetch_array ($ query); // you read one more row here.
While ($ rs = mysql_fetch_array ($ query )){

$ Keys = $ _ GET ['Keys '];
Change
$ Keys = iconv ('utf-8', 'gbk', $ _ GET ['Keys ']);

Also, mysql_query ('set names gbk') is used ');
However, the $ key variable value will be passed on the previous page because the passed value is UTF-8 and will become invalid when the SQL statement is executed.
% ". $ Keys." % changed to % ". iconv ('utf-8', 'gbk', '$ keys')." %

$ Keys = $ _ GET ['Keys '];
Change
$ Keys = iconv ('utf-8', 'gbk', $ _ GET ['Keys ']);
What can I do if I miss your mention today?

Just get to know the rule.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.