-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetHalfDate.php
57 lines (44 loc) · 1.21 KB
/
getHalfDate.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
54
55
56
57
<?php
error_reporting(0);
$tablename = $_GET['name'];
//$tablename = 'sem';
require_once "dbase_connection.php";
require_once "functions.php";
$connection = mysqli_connect($dbhost, $dbuser, $dbpassword, $dbname);
if(!$connection){
echo ('ConnectionError');
exit();
}
$query = "SELECT * FROM $tablename ";
$result = mysqli_query($connection, $query);
if (!$result) {
die("ConnectionError");
}
$dates_zero = [];
$dates_one = [];
$dates_two = [];
$dates_00 = [];
$dates_11 = [];
$dates_22 = [];
while ($row = mysqli_fetch_assoc($result)) {
if($row['status'] == 0){
$dates_00[] = ($row['date']);
}elseif($row['status'] == 2){
$dates_22[]=($row['date']);
}else{
$dates_11[]=($row['date']);
}
}
$dates_zero = yearsort($dates_00);
$dates_one = yearsort($dates_11);
$dates_two = yearsort($dates_22);
// 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);
?>