-
Notifications
You must be signed in to change notification settings - Fork 0
/
trivia_data_last24.php
34 lines (34 loc) · 1.32 KB
/
trivia_data_last24.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
<?php
header('Content-Type: text/plain; charset=UTF-8');
$servername = "localhost";
$username = "tekntehf_trivias_user";
$password = "Fo3A4QZ)*s+d";
$dbname = "tekntehf_trivias";
$minTimeStamp = (time() * 1000) - (24 * 60 * 60 * 1000);
$trivias = array();
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$lang_change = "SET NAMES utf8mb4";
if (mysqli_query($conn, $lang_change)) {
//echo "Successful: Language change. ";
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
$sql = "SELECT name, question, answer, time, winners, chat, total FROM trivia_data WHERE time > $minTimeStamp";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
$trivia = array ("hoster" => $row['name'], "question" => $row['question'], "answer" => $row['answer'], "timeStamp" => $row['time'], "winners" => $row['winners'], "chatName" => $row['chat'], "totalAmount" => $row['total']);
array_push($trivias, $trivia);
}
} else {
echo "0 results";
}
$conn->close();
echo json_encode($trivias);
?>