-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathExportToExcel_online_hod.php
More file actions
56 lines (46 loc) · 1.39 KB
/
ExportToExcel_online_hod.php
File metadata and controls
56 lines (46 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
include 'includes/connection.php';
ob_start();
session_start();
$filename = "analysis";
if(isset($_SESSION['Sql_1']))
$sql = $_SESSION['Sql_1'];
if(isset($_SESSION['Sql_2']))
$sql = $_SESSION['Sql_2'];
if(isset($_SESSION['Sql_3']))
$sql = $_SESSION['Sql_3'];
if(isset($_SESSION['Sql_4']))
$sql = $_SESSION['Sql_4'];
if(isset($_SESSION['Sql_5']))
$sql = $_SESSION['Sql_5'];
if(isset($_SESSION['Sql_6']))
$sql = $_SESSION['Sql_6'];
$result = mysqli_query($conn,$sql) or die("Couldn't execute query:<br>" . mysqli_error(). "<br>" . mysqli_errno());
$file_ending = "xls";
header("Content-Type: application/xls");
header("Content-Disposition: attachment; filename=$filename.xls");
header("Pragma: no-cache");
header("Expires: 0");
$sep = "\t";
$names = mysqli_fetch_fields($result) ;
foreach($names as $name){
print ($name->name . $sep);
}
print("\n");
while($row = mysqli_fetch_row($result)) {
$schema_insert = "";
for($j=0; $j<mysqli_num_fields($result);$j++) {
if(!isset($row[$j]))
$schema_insert .= "NULL".$sep;
elseif ($row[$j] != "")
$schema_insert .= "$row[$j]".$sep;
else
$schema_insert .= "".$sep;
}
$schema_insert = str_replace($sep."$", "", $schema_insert);
$schema_insert = preg_replace("/\r\n|\n\r|\n|\r/", " ", $schema_insert);
$schema_insert .= "\t";
print(trim($schema_insert));
print "\n";
}
?>