-
Notifications
You must be signed in to change notification settings - Fork 0
/
export_last24_data.php
42 lines (41 loc) · 1.48 KB
/
export_last24_data.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
<?php
header('Access-Control-Allow-Origin: https://gamdom.com');
header('Content-Type: text/plain; charset=UTF-8');
$currentTime = time() * 1000;
$timeLimit = $currentTime - 1 * 24 * 60 * 60 * 1000;
$last24Total = 0;
$servername = "localhost";
$username = "tekntehf_trivias_user";
$password = "Fo3A4QZ)*s+d";
$dbname = "tekntehf_trivias";
$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 "Error: " . $sql . "<br>" . mysqli_error($conn);
}
$sql = "SELECT name, question, answer, time, winners, chat, total FROM trivia_data";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
if(!is_nan(floatval($row['time'])) && !is_nan(floatval($row['total'])) && intval($row['total']) && intval($row['time']) > $timeLimit) {
if(intval($row['time'])) {
//echo intval($row['time']) . "|" . $currentTime . "\n";
$last24Total += intval($row['total']);
}
}
}
} else {
echo "Found 0 last trivias.";
}
$insertData = "INSERT INTO `trivia_stats` (`id`, `last24Total`, `startTimestamp`, `endTimestamp`) VALUES (NULL, $last24Total, $timeLimit, $currentTime)";
if (mysqli_query($conn, $insertData)) {
echo "Successfully inserted data: $last24Total";
} else {
echo "Error. Please send this data to TEKNO: " . $sql . "<br>" . mysqli_error($conn);
}
$conn->close();
?>