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