-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcourse_info.php
99 lines (90 loc) · 2.79 KB
/
course_info.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
91
92
93
94
95
96
97
98
99
<?php
$mysqli = new mysqli("localhost","foobarcs411_gwehner2","password123","foobarcs411_scheduler");
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
session_start();
$myusername = $_SESSION['username'];
$name = $_GET["course_name"];
$usefulness = $_GET["course_usefulness"];
$difficulty = $_GET["course_difficulty"];
$workload = $_GET["course_difficulty"];
/*$query = "UPDATE Course
SET
Usefulness = ('$usefulness' +
((SELECT c2.Usefulness
FROM Course c2
WHERE c2.Code = '$name')
*
(SELECT c3.Opinion_Count
FROM Course c3
WHERE c3.Code = '$name')))
/
((SELECT c4.Opinion_Count
FROM Course c4
WHERE c4.Code = '$name')
+ 1)
WHERE Code = '$name'";
$result = $mysqli->query($query);
echo $result;
$query2 = "UPDATE Course
SET
Course.Difficulty = ($difficulty +
((SELECT c2.Difficulty
FROM Course c2
WHERE c2.Code = $name)
*
(SELECT c3.Opinion_Count
FROM Course c3
WHERE c3.Code = $name)))
/
((SELECT c4.Opinion_Count
FROM Course c4
WHERE c4.Code = $name)
+ 1)
WHERE Code = $name";
$result2 = $mysqli->query($query);
echo $result2;
$query3 = "UPDATE Course
SET
Course.Workload = ($workload +
((SELECT c2.Workload
FROM Course c2
WHERE c2.Code = $name)
*
(SELECT c3.Opinion_Count
FROM Course c3
WHERE c3.Code = $name)))
/
((SELECT c4.Opinion_Count
FROM Course c4
WHERE c4.Code = $name)
+ 1)
WHERE Code = $name";
$result3 = $mysqli->query($query);
echo $result3;
$query4 = "UPDATE Course
SET Opinion_Count =
((SELECT Opinion_Count
FROM Course c2
WHERE c2.Code = '$name')
+ 1)
WHERE Code = '$name'";
$result4 = $mysqli->query($query4);
echo $result2;
*/
$query = "UPDATE Course
SET Usefulness = ('$usefulness' + (Opinion_Count * Usefulness)) / (Opinion_Count + 1),
Difficulty = ('$difficulty' + (Opinion_Count * Difficulty)) /
(Opinion_Count + 1),
Workload = ('$workload' + (Opinion_Count * Workload)) /
(Opinion_Count + 1)
WHERE Code = '$name'";
$result = $mysqli->query($query);
$query5 = "UPDATE Course
SET Opinion_Count = Opinion_Count + 1
WHERE Code = '$name'";
$result5 = $mysqli->query($query5);
echo $result5;
$mysqli->close();
?>