Test

  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
<?php
session_start();
include("Admin/MySQL_Connection.php");
#----------------[ Showing Advertisements ]-----------------
if(isset($_GET['Cat_Key']))
{
$Cat_Key = $_GET['Cat_Key'];
$sql = mysqli_query($con, "SELECT COUNT(ad_id) FROM ads WHERE ad_cat='$Cat_Key'");
}
else $sql = mysqli_query($con, "SELECT COUNT(ad_id) FROM ads");
$query = $sql;
$row=mysqli_fetch_row($query);
$rows = $row[0];
$page_rows = 6;
$last = ceil($rows/$page_rows);
if($last < 1)
{
$last = 1;
}
$pagenum = 1;
if(isset($_GET['pn']))
{
$pagenum = preg_replace('#[^0-9]#', '', $_GET['pn']);
}
if ($pagenum < 1)
{
$pagenum = 1;
}
else if ($pagenum > $last)
{
$pagenum = $last;
}
$limit = 'LIMIT ' .($pagenum - 1) * $page_rows .',' .$page_rows;
$list = '';
$sort = "ad_id DESC";
if(isset($_POST['Sort_Ads']))
{
$sortit = $_POST['Sort_Ads'];
$_SESSION['sortorder'] = $sortit;
if($sortit == "Most Recent Ads") $sort = "ad_id DESC";
else if($sortit == "Price: Low to High") $sort = "ad_price ASC";
else if($sortit == "Price: High to Low") $sort = "ad_price DESC";
}
elseif(isset($_SESSION['sortorder']))
{
$sortit = $_SESSION['sortorder'];
if($sortit == "Most Recent Ads") $sort = "ad_id DESC";
else if($sortit == "Price: Low to High") $sort = "ad_price ASC";
else if($sortit == "Price: High to Low") $sort = "ad_price DESC";
}
if(isset($_GET['Cat_Key']))
{
$Cat_Key1 = $_GET['Cat_Key'];
$_SESSION['Cat_Key_Ses'] = $Cat_Key1;
$Cat_Key = $_SESSION['Cat_Key_Ses'];
$sql = mysqli_query($con, "SELECT * FROM ads WHERE ad_cat='$Cat_Key' ORDER BY $sort $limit");
if(mysqli_num_rows($sql) == 0) $list = "<h2 style='text-align:center; background-color:#FFF;'>No results found in Category $Cat_Key!</h2>";
}
else $sql = mysqli_query($con, "SELECT * FROM ads ORDER BY $sort $limit");
$query = $sql;
$textline1 = "Ads (<b>$rows</b>)";
$textline2 = "Page <b>$pagenum</b> of <b>$last</b>";
$paginationCtrls = '';
if($last != 1)
{
if ($pagenum==1) $paginationCtrls .= '<';
else if ($pagenum > 1)
{
$previous = $pagenum - 1;
if(isset($_GET['Cat_Key'])) $paginationCtrls .= '<a href="'.$_SERVER['PHP_SELF'].'?Cat_key='.$Cat_Key.'?pn='.$previous.'"><</a>';
else $paginationCtrls .= '<a href="'.$_SERVER['PHP_SELF'].'?pn='.$previous.'"><</a>';
}
if ($pagenum==$last) $paginationCtrls .= '>';
if ($pagenum != $last)
{
$next = $pagenum + 1;
if(isset($_GET['Cat_Key'])) $paginationCtrls .= '<a href="'.$_SERVER['PHP_SELF'].'?Cat_key='.$Cat_Key.'?pn='.$next.'">></a> ';
else $paginationCtrls .= '<a href="'.$_SERVER['PHP_SELF'].'?pn='.$next.'">></a> ';
}
}
if(isset($_POST['Show_Ad_Bar']))
{
$_SESSION['Display'] = 'BAR';
}
else if(isset($_POST['Show_Ad_Box']))
{
$_SESSION['Display'] = 'BOX';
}
if (!isset($_SESSION['Display'])) $_SESSION['Display'] = 'BAR';
while($row_ads = mysqli_fetch_array($query, MYSQLI_ASSOC))
{
$ad_id = $row_ads['ad_id'];
$ad_title = $row_ads['ad_title'];
$ad_phone = $row_ads['ad_phone'];
$ad_email = $row_ads['ad_email'];
$ad_cat = $row_ads['ad_cat'];
$ad_pro = $row_ads['ad_pro'];
$ad_type = $row_ads['ad_type'];
$ad_address = $row_ads['ad_address'];
$ad_date = $row_ads['ad_date'];
$ad_time = $row_ads['ad_time'];
$ad_details = $row_ads['ad_details'];
$ad_price = $row_ads['ad_price'];
$ad_currency = $row_ads['ad_currency'];
$ad_img = $row_ads['ad_img'];
$today = date('Y/m/d', time());
$yesterday = date("Y/m/d", strtotime("-1 day"));
if($ad_date==$today) $ad_date = "Today";
else if($ad_date==$yesterday) $ad_date = "Yesterday";
if ($_SESSION['Display'] == 'BAR') $list .= "
<table id='Ad_Bar'>
<tr>
<td width='80'>$ad_date</td>
<td width='110' rowspan='3' align='center'><a href='Index.php?ad=$ad_id'><img width='100' height='80' border='0' src='User/Ad_Images/$ad_img'></img></a></td>
<td width='300'><a href='Index.php?ad=$ad_id'>$ad_title</a></td>
<td width='80'>$ad_pro</td>
</tr>
<tr>
<td width='80'>$ad_time</td>
<td width='300'>$ad_currency</td>
<td width='80'>$ad_price</td>
</tr>
<tr>
<td width='80'></td>
<td width='300'>$ad_type</td>
<td width='80'>$ad_cat</td>
</tr>
</table>
";
else if ($_SESSION['Display'] == 'BOX') $list .= "
<table id='Ad_Box'>
<tr>
<td colspan='2' align='left'>$ad_type</td>
</tr>
<tr>
<td align='center' colspan='2'><a href='Index.php?ad=$ad_id'>$ad_title</a></td>
</tr>
<tr>
<td colspan='2' align='center'><a href='Index.php?ad=$ad_id'><img width='160' height='130' border='0' src='User/Ad_Images/$ad_img'></img></a></td>
</tr>
<tr>
<td align='left'>$ad_date</td>
<td align='right'>$ad_time</td>
</tr>
<tr>
<td align='left'>$ad_price</td>
<td align='right'>$ad_currency</td>
</tr>
<tr>
<td align='left'>$ad_pro</td>
<td align='right'>$ad_cat</td>
</tr>
</table>
";
}
?>
//And the html area
<form id="formName" action="Index.php" method="POST">
<input type="submit" name="Show_Ad_Bar" onchange="document.getElementById('formName').submit()" value="bar"></input>
<input type="submit" name="Show_Ad_Box" onchange="document.getElementById('formName').submit()" value="block"></input>
<select name="Sort_Ads" id="Sort_Ads" onchange="document.getElementById('formName').submit()">
<option>Most Recent Ads</option>
<option>Price: High to Low</option>
<option>Price: Low to High</option>
</select>
</form>
<div>
<h2><?php echo $textline1; ?> Paged</h2>
<div id="pagination_controls"><?php echo $textline2; ?><?php echo $paginationCtrls; ?></div>
<p><?php echo $list; ?></p>
</div>