php 查询和分页
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 查询和分页相关的知识,希望对你有一定的参考价值。
<?php
/* Get Parameters */
$curr_url = "search?";
$url_keyword = $url_category = $url_location = "";
if(isset($_GET['q']) && !empty($_GET['q'])) {
$url_keyword = "{$_GET['q']}";
$curr_url .= "q={$url_keyword}";
}
if(isset($_GET['category']) && !empty($_GET['category'])) {
$url_category = "{$_GET['category']}";
$curr_url .= "category={$url_category}";
}
if(isset($_GET['location']) && !empty($_GET['location'])) {
$url_location = "{$_GET['location']}";
$curr_url .= "location={$url_location}";
}
// echo $curr_url;
?>
<section class="search-results--pagination">
<div class="container">
<div class="col-lg-12 text-center">
<!-- Top -->
<nav class="pagination--top">
<?php if($page != 1) { // SHOW if Page is not Page 1 ?>
<a href="<?php $prev_page = $page - 1; echo "{$curr_url}&page={$prev_page}&sort={$sort}"; ?>">
<Back
</a>
<?php } ?>
<a href="<?php echo "{$curr_url}&page={$page}&sort={$sort}"; ?>" class="active">
Page <?php echo $page; ?>
</a>
<?php if( ($page != $numpages) && ($numpages != 0)) { // SHOW if Page is not the Last Page ?>
<a href="<?php $next_page = $page + 1; echo "{$curr_url}&page={$next_page}&sort={$sort}"; ?>">
Next >
</a>
<?php } ?>
</nav>
<!-- Bottom -->
<nav class="pagination--bottom">
<?php if($numpages !== 0) { ?>
<?php if($page != 1) { // SHOW if Page is not Page 1 ?>
<a href="<?php echo "{$curr_url}&page=1&sort={$sort}"; ?>">
<<
</a>
<?php } ?>
<?php
$startpage = $page - 2;
if($startpage < 1) {
$startpage = 1;
}
$endpage = $page + 2;
if($endpage > $numpages) {
$endpage = $numpages;
}
for( $i = $startpage; $i <= $endpage; $i++ ) {
?>
<a <?php if($page == $i) { echo "class='active'"; } ?> href="<?php echo "{$curr_url}&page={$i}&sort={$sort}"; ?>"><?php echo $i; ?></a>
<?php } ?>
<?php if( ($page != $numpages) && ($numpages != 0) ) { // SHOW if Page is not the Last Page ?>
<a href="<?php echo "{$curr_url}&page={$numpages}&sort={$sort}"; ?>">
>>
</a>
<?php } ?>
<?php } ?>
</nav>
</div>
</div>
</section>
以上是关于php 查询和分页的主要内容,如果未能解决你的问题,请参考以下文章