/
data3.php
90 lines (53 loc) · 1.78 KB
/
data3.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
/**
* Created by Dickson Msaky @ Ifakara Health Insitute (2018)
**/
include_once('includes/load.php');
//setting header to json
header('Content-Type: application/json');
$prefixtable = $_SESSION['expcode']."_";
$q = $_GET['q'];
if(isset($_POST['field1'])) {
$_SESSION['f1'] = $_POST["field1"];
$_SESSION['ind'] = $_POST["field2"];
$_SESSION['FromDate'] =$_POST['FromDate'];
$_SESSION['ToDate'] =$_POST['ToDate'];
}else{
$wherecon = "";
}
$wherecon = "";
if($_SESSION['f1'] != 0){
$wherecon .= " AND ea=".$_SESSION['f1'];
}
if($_SESSION['ind'] != 0){
$wherecon .= " AND ed1.ind=".$_SESSION['ind'];
}
if($_SESSION['FromDate'] != "" && $_SESSION['ToDate'] != ""){
$wherecon .= " AND ed1.dt BETWEEN '".date('Y-m-d', strtotime($_SESSION['FromDate']))."' AND '".date('Y-m-d', strtotime($_SESSION['ToDate']))."' ";
}else if($_SESSION['FromDate'] != ""){
$wherecon .= " AND ed1.dt >= '".date('Y-m-d', strtotime($_SESSION['FromDate']))."'";
}else if($_SESSION['ToDate'] != ""){
$wherecon .= " AND ed1.dt <= '".date('Y-m-d', strtotime($_SESSION['ToDate']))."'";
}
$query="SELECT me, count(*) as frequency FROM ".$prefixtable."ed1 GROUP BY me";
//execute query
$result = $db->query($query);
//echo $query;
/*
//loop through the returned data
$data = array();
foreach ($result as $row) {
$data[] = $row;
}
//free memory associated with result
$result->close();
//now print the data
print json_encode($data); */
$label = array();
$datasets = array();
while ($row = $db->fetch_assoc($result)) {
$label[] = $row["me"];
$datasets[] = $row["frequency"];
}
$final_array = array("labels" => $label,"datasets" => $datasets);
echo json_encode($final_array);