doudai8083 2016-05-16 10:52
浏览 30

将整个页面导出为ex​​cel而不是特定查询

Okey, I have problem, I want to export data from MYSQL db to excel using PHP, but it export the whole page, not only the table from database. There is my code:

<?php


                    if(isset($_GET['submit2']))
                    {
                        $vardas=$_GET['vardas']; //to rename the file
                        header('Content-Disposition: attachment; filename='.$vardas.'.xls'); 
                        header('Cache-Control: no-cache, no-store, must-revalidate, post-check=0, pre-check=0');
                        header('Pragma: no-cache');
                        header('Content-Type: application/x-msexcel; charset=windows-1251; format=attachment;');
                        $msg="";
                        $var="";
                        //write your query      
                        $sql="SELECT laikas,Nuoroda "
        .               "FROM " . TBL_NUORODOS . " ORDER BY laikas DESC,Nuoroda";
                        $res = mysql_query($sql);
                        $numcolumn = mysql_num_fields($res); //will fetch number of field in table
                        $msg="<table><tr><td>Sl No</td>";
                        for ( $i = 0; $i < $numcolumn; $i++ ) {
                            $msg.="<td>";
                            $msg.= mysql_field_name($res, $i);  //will store column name of the table to msg variable
                            $msg.="</td>";

                        }
                        $msg.="</tr>";
                        $i=0;
                        $count=1; //used to print sl.no
                        while($row=mysql_fetch_array($res))  //fetch all the row as array
                        {

                            $msg.="<tr><td>".$count."</td>";
                            for($i=0;$i< $numcolumn;$i++)
                            {
                                $var=$row[$i]; //will store all the values of row 
                                $msg.="<td>".$var."</td>";
                            }
                            $count=$count+1;
                            $msg.="</tr>";
                        }

                        $msg.="</table>";
                        echo $msg;  //will print the content in the exel page
                    }
                    ?>

I only want to export this query : $sql="SELECT laikas,Nuoroda " . "FROM " . TBL_NUORODOS . " ORDER BY laikas DESC,Nuoroda"; to my excel Thanks

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥100 set_link_state
    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度