-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.php
236 lines (193 loc) · 11.5 KB
/
index.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
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
<?php
require_once('nav.php');
require_once('config.php');
$connection = db2_connect($dbname, $username, $password);
if (!$connection) {
die('Not connected : ' . db2_conn_error());
}
?>
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
<head>
<title>AuctionHub</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="resources/bootstrap-select/dist/css/bootstrap-select.min.css">
<style type="text/css">
/* Fixes submit button height problem in Firefox */
.tfbutton::-moz-focus-inner {
border: 0;
}
.tfclear{
clear:both;
}
#container{
padding-left: 15px;
padding-right: 15px;
}
.form-control{
width : 15em;
}
#datatable{
background-color: #FFFFFF;
}
</style>
<script type="text/javascript" src="resources/jquery-1.11.3.js"></script>
<script type="text/javascript" src="resources/bootstrap-select/dist/js/bootstrap-select.min.js"></script>
</head>
<body>
<!-- HTML for SEARCH BAR -->
<div id="container">
<table class="table table-striped table-bordered table-hover table-condensed" id="datatable">
<nav>
<ul class="pagination">
<tr>
<th>Image</th>
<th>Item</th>
<th>Current Bid</th>
<th>Number of Bids</th>
</tr>
<?php
//find out how many rows are in the table
$numRows = "Select Count(*) from $computerName.items";
$stmt3 = db2_prepare($connection, $numRows);
$result3 = db2_execute($stmt3);
$r = db2_fetch_array($stmt3);
$numrows = $r[0];
//number of rows to show per page
$rowsperpage = 10;
//find out total pages:
$totalpages = ceil($numrows / $rowsperpage);
//get the current page or set a default
if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) {
//cast var as int
$currentpage = (int) $_GET['currentpage'];
} else {
// default page num
$currentpage = 1;
}
// if current page is greater than total pages...
if ($currentpage > $totalpages) {
//set current page to the last page
$currentpage = $totalpages;
}
//if current page is less less than the first page
if ($currentpage < 1) {
//set current page to the first page
$currentpage = 1;
}
// the offset of the list, based on current page
$offset = ($currentpage - 1) * $rowsperpage;
$variable = ($offset + $rowsperpage) - 1;
//FILTERATION
if(isset($_POST['select_name'])) {
if($_POST['select_name'] == 'plowest'){
$query = "select * from(Select ROW_NUMBER() OVER(ORDER BY POST_PRICE ASC) as rn, $computerName.items.* FROM $computerName.items) where rn between $offset and $variable";
}
else if($_POST['select_name'] == 'phighest'){
$query = "select * from(Select ROW_NUMBER() OVER(ORDER BY POST_PRICE DESC) as rn, $computerName.items.* FROM $computerName.items) where rn between $offset and $variable";
}
else if($_POST['select_name'] == 'endingsoon'){
$query = "select * from(Select ROW_NUMBER() OVER(ORDER BY END_DATE ASC) as rn, $computerName.items.* FROM $computerName.items) where rn between $offset and $variable";
}
else if($_POST['select_name'] == 'newlylisted'){
$query = "select * from(Select ROW_NUMBER() OVER(ORDER BY END_DATE DESC) as rn, $computerName.items.* FROM $computerName.items) where rn between $offset and $variable";
}
else{
$query = "select * from(Select ROW_NUMBER() OVER() as rn, $computerName.items.* FROM $computerName.items) where rn between $offset and $variable";
}
}
//IF NOT FILTER IS SELECTED
else{
$query = "select * from(Select ROW_NUMBER() OVER() as rn, $computerName.items.* FROM $computerName.items) where rn between $offset and $variable";
}
$stmt = db2_prepare($connection, $query);
$result = db2_execute($stmt);
if ($stmt) {
while ($row = db2_fetch_array($stmt)) {
//$query2 = "select * from(Select ROW_NUMBER() OVER() as rn, $computerName.bids.* FROM $computerName.bids) where rn between $offset and $variable";
$query2 = "Select highest_bid_amount, number_of_bids from $computerName.bids where item_id =" . $row[1];
$stmt2 = db2_prepare($connection, $query2);
$result2 = db2_execute($stmt2);
$row2 = db2_fetch_array($stmt2);
echo "<tr>";
echo "<td><center><a href=\"product.php?id=" . $row[1] . "\"><image src='" . $row[8] . "' width = 175 height = 175 </image></a></center></td>";
echo "<td><center><a href=\"product.php?id=" . $row[1] . "\">" . $row[2] . "</a></center></td>";
echo "<td>" . $row2[0] . "</td>";
echo "<td>" . $row2[1] . "</td>";
echo "</tr>";
}
}
/* * **** build the pagination links ***** */
// range of num links to show
$range = 2;
//if not on page 1, dont show back links
?>
<!--drop down menu-->
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method='post' name='form_filter' >
Filter By:
<select name ="select_name" class="form-control">
<option value = "default">...</option>
<option value = "plowest">Price Lowest</option>
<option value = "phighest">Price Highest</option>
<option value ="endingsoon">Ending Soon</option>
<option value = "newlylisted">Newly Listed</option>
</select>
<input type='submit' value = 'Filter'>
</form>
<nav>
<ul class="pagination">
<?php
if ($currentpage > 1) {
//show << to go back pages
// echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'><<</a> ";
echo"<li class='enabled'><a href='{$_SERVER['PHP_SELF']}?currentpage=1' aria-label='Previous'><span aria-hidden='true'>«</span></a></li>";
// get previous page num
$prevpage = $currentpage - 1;
// show < link to go back to 1 page
//echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage' ><</a> ";
}//end if
// loop to show links to range of pages around current page
for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) {
// if it's a valid page number...
if (($x > 0) && ($x <= $totalpages)) {
// if we're on current page...
if ($x == $currentpage) {
// 'highlight' it but don't make a link
//echo " [<b>$x</b>] ";
echo"<li class='active'><a href='$x'>$x <span class='sr-only'>(current)</span></a></li>";
// if not current page...
} else {
// make it a link
//echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> ";
echo"<li><a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a></li>";
} // end else
} // end if
}//end for
// if not on last page, show forward and last page links
if ($currentpage != $totalpages) {
// get next page
$nextpage = $currentpage + 1;
// echo forward link for next page
// echo forward link for lastpage
//echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>>></a> ";
echo"<li> <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages' aria-label='Next'><span aria-hidden='true'>»</span> </a>";
} // end if
/* * **** end build pagination links ***** */
?>
</table>
</ul>
</nav>
</div>
<script type="text/javascript">
$(function() {
//$('.selectpicker').selectpicker();
});
</script>
</body>
</html>