forked from chriszhou1992/ABCD
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshowSuggestedBasedOnLike.php
97 lines (80 loc) · 3.83 KB
/
showSuggestedBasedOnLike.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
<?php
session_start();
$username = $_SESSION["user"];
require_once "classes/connecToDB.php";
$con = connectToDB();
if($con === false):
return;
endif;
$sql = "SELECT gamesMightLike FROM users WHERE email = '$username'";
$result = mysqli_query($con, $sql);
if(!$result) {
die('Error: ' . mysqli_error($con));
}
$row = mysqli_fetch_array($result);
$games = $row['gamesMightLike'];
showSuggestedBasedOnLike($con, $games);
function showSuggestedBasedOnLike($con, $games) {
if(strlen($games) === 0):
echo "<div class='alert alert-white'><i class='fa fa-lightbulb-o'></i>  Ooops, there is currently no suggestion on games that you might like based on the games you liked.</div>";
return;
endif;
$removeID = 0;
$games = explode("<br>", $games);
$games = array_slice($games, 1);
foreach($games as $g) {
$g = addslashes($g);
$sql = "SELECT * FROM games WHERE name = '$g'";
$result = mysqli_query($con, $sql);
if(!$result) {
die('Error: ' . mysqli_error($con));
}
$row = mysqli_fetch_array($result);
if($row) {
$ranked[$g] = $row['num_likes'];
} else {
$notInDataBase[] = $g;
}
}
if(isset($ranked)) {
arsort($ranked);
foreach($ranked as $g => $k):
$sql = "SELECT * FROM games WHERE name = '$g'";
$result = mysqli_query($con, $sql);
if(!$result) {
die('Error: ' . mysqli_error($con));
}
$row = mysqli_fetch_array($result);
$imageSrc = $row['imageURL'];
echo "<div class='removeDiv'><img src='$imageSrc' alt='Loading...' style='width: 50px; 'height: 70px;>  ";
$name = $row['name'];
$send = str_replace("'", "!-!-!", $name);
echo "<span class='games' name='$send'>$name".'<span class="displayLikes float-right" style="margin-top:19px;">Total Likes: '.$row['num_likes'].'</span>'."</span><hr>";
$brief = $row['brief'];
echo "$brief<hr>";
$g = stripslashes($g);
$gameName = str_replace(" ", "!-!-!", $g);
echo '<button type="button" class="btn btn-default dislikeButton" id='.$removeID.' name='.$gameName.' style="margin-right:5px;">'
. '<i class="fa fa-thumbs-down"></i>  <span class="justLike">Do not suggest</span><span class="like"> '.$g." </span>"." <span class='justLike'>again</span>"
. "</button>";
echo '<button type="button" class="btn btn-default removeButton" id='.$removeID.' name='.$gameName.'>'
. '<i class="fa fa-trash-o"></i>  <span class="justLike">Remove</span> </span>'." <span class='justLike'>from the list for now</span>"
. "</button><hr></div>";
$removeID += 1;
endforeach;
}
if(isset($notInDataBase)):
foreach($notInDataBase as $g):
$g = stripslashes($g);
$gameName = str_replace(" ", "!-!-!", $g);
echo "<div class='removeDiv'><span class='gamesNotIn' name=''>$g</span><hr>";
echo '<button type="button" class="btn btn-default dislikeButton" id='.$removeID.' name='.$gameName.' style="margin-right:5px;">'
. '<i class="fa fa-thumbs-down"></i>  <span class="justLike">Do not suggest</span><span class="like"> '.$g." </span>"." <span class='justLike'>again</span>"
. "</button>";
echo '<button type="button" class="btn btn-default removeButton" id='.$removeID.' name='.$gameName.'>'
. '<i class="fa fa-trash-o"></i>  <span class="justLike">Remove</span> </span>'." <span class='justLike'>from the list for now</span>"
. "</button><hr></div>";
$removeID += 1;
endforeach;
endif;
}