-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction.php
More file actions
34 lines (29 loc) · 992 Bytes
/
Copy pathfunction.php
File metadata and controls
34 lines (29 loc) · 992 Bytes
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
<?php
function userRating($userId, $bookId, $conn)
{
$average = 0;
$avgQuery = "SELECT rate FROM rating WHERE StudentID = '" . $userId . "' and ISBN = '" . $bookId . "'";
$total_row = 0;
if ($result = mysqli_query($conn, $avgQuery)) {
// Return the number of rows in result set
$total_row = mysqli_num_rows($result);
} // endIf
if ($total_row > 0) {
foreach ($result as $row) {
$average = round($row["rate"]);
} // endForeach
} // endIf
return $average;
}
// endFunction
function totalRating($bookId, $conn)
{
$totalVotesQuery = "SELECT * FROM rating WHERE ISBN = '" . $bookId . "'";
if ($result = mysqli_query($conn, $totalVotesQuery)) {
// Return the number of rows in result set
$rowCount = mysqli_num_rows($result);
// Free result set
mysqli_free_result($result);
} // endIf
return $rowCount;
}//endFunction