-
Notifications
You must be signed in to change notification settings - Fork 0
/
device_report_export.php
50 lines (44 loc) · 1.49 KB
/
device_report_export.php
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
<?php
include("includes/config.inc.php");
include("includes/crosssite.inc.php");
header("Content-Type: text/csv");
header("Content-Disposition:attachment;filename=exported-data.csv");
$select_table = mysql_query("SELECT A.id as DeviceId,A.imei_no as IMEI, A.company_id as CompId, B.branch_id as Branch_name, A.status as status, A.assignstatus as branch_asgn_status, B.branch_id as Branch_name , D.CompanyName as branch, B.technician_assign_status as technician_asgn_status, C.technician_id as TechnicianId, E.First_Name as fname, E.Last_Name as lname
FROM tbl_device_master as A
LEFT OUTER JOIN tbl_device_assign_branch as B
ON A.id = B.device_id
LEFT OUTER JOIN tbl_device_assign_technician as C
ON B.device_id = C.device_id
LEFT OUTER JOIN tblbranch as D
ON B.branch_id = D.id
LEFT OUTER JOIN tbluser as E
ON C.technician_id = E.id ORDER BY A.id");
$rows = mysql_fetch_assoc($select_table);
if($rows)
{
getcsv(array_keys($rows));
}
while($rows)
{
getcsv($rows);
$rows = mysql_fetch_assoc($select_table);
}
// get total number of fields present in the database
function getcsv($no_of_field_names)
{
$separate = '';
// do the action for all field names as field name
foreach ($no_of_field_names as $field_name)
{
if (preg_match('/\\r|\\n|,|"/', $field_name))
{
$field_name = '' . str_replace('', $field_name) . '';
}
echo $separate . $field_name;
//sepearte with the comma
$separate = ',';
}
//make new row and line
echo "\r\n";
}
?>