-
Notifications
You must be signed in to change notification settings - Fork 0
/
getHalfDateOriginal.php
53 lines (42 loc) · 1.22 KB
/
getHalfDateOriginal.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
53
<?php
error_reporting(0);
$tablename = $_GET['name'];
require_once "dbase_connection.php";
$connection = mysqli_connect($dbhost, $dbuser, $dbpassword, $dbname);
// test for connection
/*if (mysqli_connect_errno()) {
die("Database connection failed: " .
mysqli_connect_error() .
" ( " . mysqli_connect_errno() . ")");
}*/
if(!$connection){
echo ('ConnectionError');
exit();
}
$query = "SELECT * FROM $tablename ";
$result = mysqli_query($connection, $query);
if (!$result) {
die("ConnectionError");
}
$dates_zero = [];
$dates_one = [];
$dates_two = [];
while ($row = mysqli_fetch_assoc($result)) {
if($row['status'] == 0){
$dates_zero[] = strtotime($row['date'])*1000;
}elseif($row['status'] == 2){
$dates_two[]=strtotime($row['date'])*1000;
}else{
$dates_one[]=strtotime($row['date'])*1000;
}
}
// compare arrays zero and two if in both arrays remove from both
// and add to onr array
$match=array_intersect($dates_zero,$dates_two);
$dates_zero=array_values(array_diff($dates_zero,$match));
$dates_one=array_merge($dates_one,$match);
$dates_two=array_values(array_diff($dates_two,$match));
echo json_encode([ $dates_zero,$dates_one,$dates_two]);
mysqli_free_result($result);
mysqli_close($connection);
?>