-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfetchAlerts.php
43 lines (37 loc) · 1011 Bytes
/
fetchAlerts.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
<?php
define('HOST','localhost');
define('USER','root');
define('PASS','');
define('DB','lids');
if(isset($_GET["count"]))
$count=$_GET["count"];
if(isset($_GET["alertpriority"]))
$alertpriority=$_GET["alertpriority"];
if(!isset($count) && !isset($alertpriority))
die("invalid query parameters");
if(isset($count) && !isset($alertpriority))
{
$sql = "SELECT * FROM tb_alerts ORDER BY timestampMs DESC LIMIT $count ;";
}
else if(!isset($count) && isset($alertpriority))
{
$sql = "SELECT * FROM tb_alerts WHERE AlertPriority=$alertpriority ;";
}
else if(isset($count) && isset($alertpriority))
{
$sql = "SELECT * FROM tb_alerts WHERE AlertPriority=$alertpriority ORDER BY timestampMs DESC LIMIT $count ;";
}
$con = mysqli_connect(HOST,USER,PASS,DB);
$res = mysqli_query($con,$sql);
$nrows = mysqli_num_rows($res);
$fin=array();
while($nrows--)
{
$row=mysqli_fetch_assoc($res);
array_push($fin,$row);
//print($data[0]);
}
echo json_encode($fin);
// print(json_encode($row));
mysqli_close($con);
?>