我的搜索系统有分页问题,我的搜索系统将结果限制为10,所以如果我的搜索结果是13,那么在第一页中它会给我10个结果但是当我点击第二页时我的网址将成为search.php?page = 2,其他3个结果将消失,但如果我再次点击搜索按钮,其他3个搜索结果将会显示。
这是我的search.php:
<div class ="search-left-container">
<div class ="search-bar-container">
<form class ="search-form" method="POST" id="search-form">
<div class ="search-bar">
<input type ="text" name="search" id="search" class ="form-control" placeholder ="search...">
</div><div class ="search-btn">
<input type ="submit" name="submit" id="searchButton" class ="form-control content-btn glyphicon-search" value ="go">
</div>
</form>
</div>
<hr>
<div class ="search-content-container" id="search-container">
<table class="table table-hover" id="resultTable">
<?php
if(isset($_GET['page'])) {
$page = $_GET['page'];
if($page == "" or $page == "1") {
$page1 = 0;
} else {
$page1 = ($page*10)-10;
}
} else {
$page1 = 0;
}
if($filter == "post" && $time == "all" && $status == "all") {
$result2 = mysqli_query($connection,"SELECT * FROM post WHERE title LIKE '%$search%' LIMIT $page1, 10") or die(mysqli_error($connection));
$count2 = mysqli_num_rows($result2);
if($count2>0) {
while($row2= mysqli_fetch_array($result2)){
$postID = $row2['id'];
$result3 = mysqli_query($connection, "SELECT * FROM user_post WHERE post_id = '$postID'") or die(mysqli_error($connection));
while($row3 = mysqli_fetch_array($result3)) {
$getUserName = mysqli_query($connection, "SELECT * FROM user WHERE id = '".$row3['user_id']."'")or die(mysqli_error($connection));
while($row4 = mysqli_fetch_array($getUserName)) { ?>
<div class ="post-container" id="search-container">
<div class ="post-header-container">
<div class ="post-header">
<a href ="post.php?id=<?php echo urlencode($row2['id']);?>&user=<?php echo $row3['user_id']; ?>">
<p class ="post-header-font"><?php echo ($row2['title']); ?></p>
</a>
</div>
<div class ="post-user">
<p class ="faded-font">by : <a href="user.php?user=<?php echo $row3['user_id']; ?>"><?php echo $row4['username']; ?></a></p>
</div>
</div>
<div class ="post-content-container">
<p class ="post-content-font">
<?php echo ($row2['summary']); ?>
</p>
</div>
<div class ="post-info-container">
<div class ="post-info">
<span class ="glyphicon glyphicon-eye-open"> views: <?php echo ($row2['views']);?></span>
</div><div class ="post-info">
<span class ="glyphicon glyphicon-pencil"> answers:</span>
</div><div class ="post-info">
<span class ="glyphicon glyphicon-ok"> status: <?php echo ($row2['status']);?></span>
</div>
</div>
</div><?php
}
}
}?>
<div class ="pagination">
<?php
$result2 = mysqli_query($connection,"SELECT * FROM post WHERE title LIKE '%$search%'") or die(mysqli_error($connection));
$postNum= mysqli_num_rows($result2);
$a=ceil($postNum/10);
if(isset($page)){
for($i = max(1, $page - 5); $i <= min($page + 5, $a); $i++){
?><div class ="pagination-selection"><a href="search.php?page=<?php echo ($i); ?>"><?php echo ($i);?></a></div><?php
}
}else{
for($i = max(1, 1 - 5); $i <= min(1 + 5, $a); $i++){
?><div class ="pagination-selection"><a href="search.php?page=<?php echo ($i); ?>"><?php echo ($i);?></a></div><?php
}
}
?>
</div><?php
}
}?>
</table>
</div><div class ="search-right-container">
<div class ="search-filter-container">
<div class ="search-filter-header featured-header">
<label class ="featured-font">filter by:</label>
</div>
<div class ="search-filter-content">
<form class ="search-form" method="POST">
<label class ="radio filter-font">
<input type ="radio" name ="filter" value ="post" form="search-form" <?php if(isset($filter) && $filter == 'post') echo 'checked = "checked"'; ?>>post
</label>
</form>
</div>
</div>
<div class ="search-time-container">
<div class ="search-time-header featured-header">
<label class ="featured-font">time</label>
</div>
<div class ="search-time-content">
<form class ="search-form">
<label class ="radio filter-font">
<input type ="radio" name ="time" value ="all" form="search-form" checked ="checked">all
</label>
</form>
</div>
</div>
<div class ="search-status-container">
<div class ="search-status-header featured-header">
<label class ="featured-font">status</label>
</div>
<div class ="search-status-content">
<form class ="search-form">
<label class ="radio filter-font">
<input type ="radio" name ="status" value ="all" checked ="checked" form="search-form">all
</label>
</form>
</div>
</div>
</div><?php
include 'footer.php';
?>