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

时间:2016-05-16 10:52:13

标签: php mysql

Okey,我有问题,我想使用PHP将数据从MYSQL db导出到excel,但它导出整个页面,而不仅是数据库中的表。 有我的代码:

<?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
                    }
                    ?>

我只想导出此查询:$ sql =“SELECT laikas,Nuoroda”         。 “来自”。 TBL_NUORODOS。 “按照laikas DESC,Nuoroda订购”;我的擅长 感谢

0 个答案:

没有答案