-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexport.php
More file actions
108 lines (103 loc) · 3.18 KB
/
export.php
File metadata and controls
108 lines (103 loc) · 3.18 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
require_once 'Dbconnect.php';
//Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
//check connection
if($conn->connect_error){
die("Connection Error: " . $conn->connect_error);
}
//echo "ID";
if(isset($_POST['submit'])){
if($_POST['option'] == 'toate'){
$result = mysqli_query($conn, "SELECT * FROM monitor");
$result_1 = mysqli_query($conn, "SELECT * FROM pc");
$result_2 = mysqli_query($conn, "SELECT * FROM imprimanta");
$result_3 = mysqli_query($conn, "SELECT * FROM ups");
$result_4 = mysqli_query($conn, "SELECT * FROM scaner");
$result_5 = mysqli_query($conn, "SELECT * FROM compimp");
$result_7 = mysqli_query($conn, "SELECT * FROM amg_assets");
$result_8 = mysqli_query($conn, "SELECT * FROM turn_aps");
//$result_6 = mysqli_query($conn, "SELECT * FROM compipc");
if (!$result) die('Couldn\'t fetch records');
if (!$result_1) die('Couldn\'t fetch records');
if (!$result_2) die('Couldn\'t fetch records');
if (!$result_3) die('Couldn\'t fetch records');
if (!$result_4) die('Couldn\'t fetch records');
$num_fields = mysqli_num_fields($result);
$headers = array();
for ($i = 0; $i < $num_fields; $i++)
{
//$headers[] = mysqli_fetch_field($result,$i);
}
$fp = fopen('php://output', 'w');
if ($fp && $result)
{
header('Content-Type: text/csv');
header('Content-Disposition: attachment; filename=inventar.csv');
header('Pragma: no-cache');
header('Expires: 0');
fputcsv($fp, array('id', 'Serial Number', 'Descriere', 'Locatie','AMG', 'Status', 'Capex', 'Numar Inv FAR', 'Observatii', 'Pret'));
while ($row = mysqli_fetch_row($result))
{
fputcsv($fp, array_values($row));
}
while ($row = mysqli_fetch_row($result_1))
{
fputcsv($fp, array_values($row));
}
while ($row = mysqli_fetch_row($result_2))
{
fputcsv($fp, array_values($row));
}
while ($row = mysqli_fetch_row($result_3))
{
fputcsv($fp, array_values($row));
}
while ($row = mysqli_fetch_row($result_4))
{
fputcsv($fp, array_values($row));
}
while ($row = mysqli_fetch_row($result_5))
{
fputcsv($fp, array_values($row));
}
//while ($row = mysqli_fetch_row($result_6))
//{
//fputcsv($fp, array_values($row));
//}
while ($row = mysqli_fetch_row($result_7))
{
fputcsv($fp, array_values($row));
}
while ($row = mysqli_fetch_row($result_8))
{
fputcsv($fp, array_values($row));
}
die;
}
}else{
$result = mysqli_query($conn, "SELECT * FROM ".$_POST['option']."");
if (!$result) die('Couldn\'t fetch records');
$num_fields = mysqli_num_fields($result);
$headers = array();
for ($i = 0; $i < $num_fields; $i++)
{
//$headers[] = mysqli_fetch_field($result,$i);
}
$fp = fopen('php://output', 'w');
if ($fp && $result)
{
header('Content-Type: text/csv');
header('Content-Disposition: attachment; filename='.$_POST['option'].'.csv');
header('Pragma: no-cache');
header('Expires: 0');
fputcsv($fp, array('id', 'Serial Number', 'Descriere', 'Locatie','AMG', 'Status', 'Capex', 'Numar Inv FAR','Observatii', 'Pret'));
while ($row = mysqli_fetch_row($result))
{
fputcsv($fp, array_values($row));
}
die;
}
}
}
?>