我一直试图将这项工作推迟一段时间。我有一个<select
标记用于显示页面上的结果数量。显然,查询可以显示所有行,但是当我转到第二页时,它不再起作用。我已经检查了一个关于使用$_REQUEST
变量但没有用的帖子。
FORM
<form method="POST" action="test.php" class="navbar-form navbar-left">
<div class="form-group">
<select class="form-control" id="adNum" name="showAdsOptions" aria-describedby="categoryHelp">
<option value="10">Show 10 ads per page</option>
<option value="15">Show 15 ads per page</option>
<option value="20">Show 20 ads per page</option>
</select>
<input type="submit" name="filterAds" class="form-control" value="Go" />
</div>
</form>
表格
<table class="table table-bordered">
<?php
include 'admin/script/connection.php';
$limit = 5;
$counter = 1;
$me = $_SESSION['user'];
$selectSQL = "SELECT * FROM user_pending_ads WHERE User_Name='$me'";
$result = $conn->query($selectSQL);
$total = $result->num_rows;
if (isset($_GET['p']) == null) {
$p = 0;
} else {
$p = $_GET['p'];
if($p == 1) {
$p = $p-1;
} else {
$p = ($p-1) * $limit;
}
}
if ($limit > $total) {
$nop = 1;
} else {
$nop = $total/$limit;
}
$nop = ceil($nop);
$display = "SELECT * FROM user_pending_ads WHERE User_Name='$me' LIMIT $p, $limit";
// SEARCH QUERY
if (isset($_GET['searchAds'])) {
if (isset($_GET['q']) == null) {
$display = "SELECT * FROM user_pending_ads WHERE User_Name='$me' LIMIT $p, $limit";
} else {
$search = $_GET['q'];
if ($search == "") {
$display = "SELECT * FROM user_pending_ads WHERE User_Name='$me' LIMIT $p, $limit";
} else {
$display = "SELECT * FROM user_pending_ads WHERE User_Name='$me' AND Ad_Title LIKE '%$search%' LIMIT $p, $limit";
}
}
}
// IF SHOW # ADS PER PAGE IS SET AND GO IS CLICKED
if (isset($_POST['filterAds']) == true) {
$opt = $_REQUEST['showAdsOptions'];
$display = "SELECT * FROM user_pending_ads WHERE User_Name='$me' LIMIT $p, $opt";
}
$getdisplay = $conn->query($display);
while ($col = $getdisplay->fetch_assoc()) {
...
}
?>
</table>
分页
<ul class="pagination">
<?php
if ($total >= 1) {
?>
<li><a href="?p=1" class="btn btn-info">First</a></li>
<?php
for ($i = 1; $i <= $nop; $i++) {
?>
<li><a href="?p=<?php echo $i ?>" class="btn btn-info"><?php echo $i ?></a></li>
<?php
}
?>
<li><a href="?p=<?php echo $nop ?>" class="btn btn-info">Last</a></li>
<?php
}
?>
</ul>