-
Notifications
You must be signed in to change notification settings - Fork 3
/
get_news.php
40 lines (40 loc) · 1.17 KB
/
get_news.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
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
$msg = "";
$success=false;
$interval = 45;//seconds
require_once 'db_functions.php';
$event = "";
$conn = connect_db();
if(gettype($conn) == 'string') {
$$msg = "DB Error: ".$conn;
} else {
$cur_time = time();
$query = "SELECT `time_started` from `event_details` WHERE `id`=1";
if(!$result = $conn->query($query)) {
$msg = "DB Error: " . $conn->error;
} else {
while($row = $result->fetch_assoc()) {
$time_started = $row['time_started']+(60);
}
$event_id = ceil(($cur_time - $time_started)/$interval);
$query = "SELECT `event` from `news` WHERE `id`=$event_id LIMIT 1";
if(!$result = $conn->query($query)) {
$msg = "DB Error: (Error fetching news)" . $conn->error;
} else {
while($row = $result->fetch_assoc()) {
$event = $row['event'];
}
$msg = "News Event fetched successfully";
$success = true;
}
}
close_db($conn);
}
if($success)
echo json_encode(Array('success'=>1,'event_id'=>$event_id,'event'=>$event),JSON_PRETTY_PRINT,JSON_UNESCAPED_SLASHES);
else
echo json_encode(Array('success'=>0,'message'=>$msg),JSON_PRETTY_PRINT,JSON_UNESCAPED_SLASHES);
?>