-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwatchlist.php
More file actions
137 lines (107 loc) · 4.14 KB
/
watchlist.php
File metadata and controls
137 lines (107 loc) · 4.14 KB
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?php
include_once("header.php");
require("utilities.php");
require_once "config.php";
?>
<?php
// Check connection
if ($link->connect_error) {
die("Connection failed: " . $link->connect_error);
}
$id = $_SESSION['userID'];
$sql_total = "SELECT * FROM watch_list WHERE user_id = '$id' ";
$rs_result = $link->query($sql_total);
[$max_page,$results_per_page,$start_from] = page_calculation($rs_result);
$mysql= "SELECT b.item_id, b.title, b.description, b.current_price, b.num_bids, b.end_date
FROM watch_list AS a LEFT JOIN item AS b ON a.item_id = b.item_id
WHERE a.user_id ='$id'LIMIT $start_from,$results_per_page";
$result = $link->query($mysql);
if (!isset($_GET['page'])) {
$curr_page = 1;
}
else {
$curr_page = $_GET['page'];
}
?>
<div class="container mt-5">
<!-- TODO: If result set is empty, print an informative message. Otherwise... -->
<ul class="list-group">
<!-- TODO: Use a while loop to print a list item for each auction listing
retrieved from the query -->
<?php
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
$list_id = $row["item_id"];
$title = $row["title"];
$description = $row["description"];
$current_price = $row["current_price"];
$num_bids = $row["num_bids"];
try {
$end_time = new DateTime($row["end_date"]);
} catch (Exception $e) {
}
$item_id = $row["item_id"];
print_listing_li($item_id, $title, $description, $current_price, $num_bids, $end_time);
}
} else {
echo "0 results";
die();
}
?>
</ul>
<!-- Pagination for results listings -->
<nav aria-label="Search results pages" class="mt-5">
<ul class="pagination justify-content-center">
<?php
// Copy any currently-set GET variables to the URL.
$querystring = "";
foreach ($_GET as $key => $value) {
if ($key != "page") {
$querystring .= "$key=$value&";
}
}
$high_page_boost = max(3 - $curr_page, 0);
$low_page_boost = max(2 - ($max_page - $curr_page), 0);
$low_page = max(1, $curr_page - 2 - $low_page_boost);
$high_page = min($max_page, $curr_page + 2 + $high_page_boost);
if ($curr_page != 1) {
echo('
<li class="page-item">
<a class="page-link" href="watchlist.php?' . $querystring . 'page=' . ($curr_page - 1) . '" aria-label="Previous">
<span aria-hidden="true"><i class="fa fa-arrow-left"></i></span>
<span class="sr-only">Previous</span>
</a>
</li>');
}
for ($i = $low_page; $i <= $high_page; $i++) {
if ($i == $curr_page) {
// Highlight the link
echo('
<li class="page-item active">');
}
else {
// Non-highlighted link
echo('
<li class="page-item">');
}
// Do this in any case
echo('
<a class="page-link" href="watchlist.php?' . $querystring . 'page=' . $i . '">' . $i . '</a>
</li>');
}
if ($curr_page != $max_page) {
echo('
<li class="page-item">
<a class="page-link" href="watchlist.php?' . $querystring . 'page=' . ($curr_page + 1) . '" aria-label="Next">
<span aria-hidden="true"><i class="fa fa-arrow-right"></i></span>
<span class="sr-only">Next</span>
</a>
</li>');
}
$link->close();
?>
</ul>
</nav>
</div>
<?php include_once("footer.php")?>