-
Notifications
You must be signed in to change notification settings - Fork 1
/
getHistoryData.php
77 lines (58 loc) · 1.91 KB
/
getHistoryData.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
<?php
require("common.php");
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
} else {
//echo "db is connected";
}
//session_start();
$user = $_SESSION['username'];
$sql = "SELECT id FROM userinfo WHERE username = '$user';";
$result = $conn->query($sql);
$row = $result->fetch_assoc();
$userid = $row["id"];
if(empty($_SESSION['user'])) {
header("Location: index1.php");
die("Redirecting to index1.php");
}
//count how many distinct date need to be displayed on graph
$getdatecount = "SELECT COUNT(DISTINCT curtime) AS count
FROM `answers` WHERE UserID = $userid";
$resdates = $conn->query($getdatecount);
if ($resdates->num_rows > 0) {
while($rowdates = $resdates->fetch_assoc()){
$count = $rowdates["count"];
}
}
//echo $count;
//get all the date data as an array
$date = array();
$getdates = "SELECT DISTINCT curtime
FROM answers
WHERE UserID = $userid;";
$resdates = $conn->query($getdates);
for($x = 0; $x < $count; $x++) {
while($rowdates = $resdates->fetch_assoc()){
$date[$x] = $rowdates["curtime"];
echo $date[$x];
}
}
//count the yes, no and don't number in the array
//count how many yes in total through three sections
$yesarray = array();
$yes = "Yes";
for ($x = 0; $x < $count; $x++) {
if ( isset($date[$x])) {
$getquestionyes = "SELECT COUNT(AnswerID) AS yescount
FROM answers, questions
WHERE answers.UserID = $userid AND answers.QuestionID = questions.QuestionID
AND Answer = $yes AND curtime = $date[$x];";
$resdata = $conn->query($getquestionyes);
while ($rowdata = $resdata->fetch_assoc()) {
$questionyes = $rowdata["yescount"];
}
}
}
//create data table
?>