-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfriendlist.php
66 lines (56 loc) · 1.95 KB
/
friendlist.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
<?php
/*********************************************
*? NAME : SanJeosutin
*? TITLE : functions.php
*? DESCRIPTION : list user's friend on this page
*? CREATED ON : 24-09-2020
*? EDITED ON : 21-10-2020
*********************************************/
include("functions/header.php");
include("functions/functions.php");
if(!isset($_SESSION['login'])){
header("Location: index.php");
exit();
}
echo "
<p>Welcome, <strong>".$_SESSION['name']."</strong>!</p>
<p>Here's your friends list. Currently you have ".$_SESSION['noOfFriends']." friends!</p>
";
if($_SESSION['noOfFriends'] == 0){
echo "<p>Sorry about that 😬</p>";
}
//if pageNum doesn't exist, set var pageNum as a GET method
//else set it as 1
if(isset($_GET['pageNum'])){
$pageNum = $_GET['pageNum'];
}else{
$pageNum = 1;
}
require_once("functions/settings.php");
$numFriendsPerPage = 5;
$offSet = ($pageNum-1) * $numFriendsPerPage;
$totalFriends = $_SESSION['noOfFriends'];
//round totalPage as a whole number
$totalPage = ceil($totalFriends / $numFriendsPerPage);
if($totalFriends > 5){
if($pageNum < 2){
echo "<a class='button' href='?pageNum=".($pageNum+1)."'> Next </a>";
}elseif($pageNum > $totalPage-1){
echo "<a class='button' href='?pageNum=".($pageNum-1)."'> Prev </a>";
}else{
echo "<a class='button' href='?pageNum=".($pageNum-1)."'> Prev </a>";
echo "<a class='button' href='?pageNum=".($pageNum+1)."'> Next </a>";
}
}
?>
<form method="POST" action="<?php echo $_SERVER['PHP_SELF'] ?>">
<table class="friendList">
<?php
require_once("functions/settings.php");
showFriendsList($conn, $offSet, $numFriendsPerPage);
?>
</table>
</form>
<?php
include("functions/footer.php");
?>