<?php 
include 'dbc.php';
$sql = "SELECT * FROM admission";
$result1=$conn->query($sql);

$columnHeader = ''; 
//$columnHeader = "Id" . "\t" . "Name" . "\t" . "Father Name" . "\t" . "Class Name" . "\t" . " Section" . "\t" . "Cell 1" . "\t" . "Whatsapp" . "\t" . "Cell 2" . "\t" ; 
$setData = ''; 
while($rec = $result1->fetch_assoc()) { 
$rowData = ''; 
foreach ($rec as $value) { 
$value = '"' . $value . '"' . "\t"; 
$rowData .= $value; 
} 
$setData .= trim($rowData) . "\n"; 
} 
header("Content-type: application/octet-stream"); 
header("Content-Disposition: attachment; filename=User_records.xls"); 
header("Pragma: no-cache"); 
header("Expires: 0"); 
echo ucwords($columnHeader) . "\n" . $setData . "\n"; 
?>   