-
Notifications
You must be signed in to change notification settings - Fork 0
/
getdevicesforuser.php
executable file
·52 lines (48 loc) · 1.96 KB
/
getdevicesforuser.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
51
52
<?php
require_once('config.php');
require_once('loginneeded.php');
$sql = "SELECT * FROM devices WHERE userid='$fuserid'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
$workingcount['working']=0;
$workingcount['faulty']=0;
while($row = $result->fetch_assoc()) {
//device_id,device_type_id,device_makeid,device_hbnumber_device_working
$device['id']=$row['device_id'];
$typeid=$row['device_makeid'];
$device['type_id']=$typeid;
$sql="SELECT * FROM device_types WHERE device_type_id='$typeid'";
$resulttype = mysqli_query($conn,$sql);
$rowtype = mysqli_fetch_row($resulttype);
$device['type']=$rowtype[1];
$makeid=$row['device_makeid'];
$device['makeid']=$makeid;
$sql="SELECT * FROM device_makes WHERE device_make_id='$makeid'";
$resultmake = mysqli_query($conn,$sql);
$rowmake = mysqli_fetch_row($resultmake);
$device['make']=$rowmake[1];
$device['hbnumber']=$row['device_hbnumber'];
$device['comment']=$row['device_comment'];
$working=$row['device_working'];
if ($working) {
$device['working']="Working";
$workingcount['working']++;
} else {
$device['working']="Faulty";
$workingcount['faulty']++;
}
$userid=$row['userid'];
$device['userid']=$userid;
$roomid=$row['roomid'];
$device['roomid']=$roomid;
$sql = "SELECT first_name, last_name FROM users WHERE userid='$userid' limit 1";
$result2 = $conn->query($sql);
$row2 = $result2->fetch_assoc();
$device['first_name']=$row2['first_name'];
$device['last_name']=$row2['last_name'];
$devices[]=$device;
}
}
$smarty->assign("devices", $devices);
$smarty->assign("workingcount", $workingcount);