我有一个生成列表页数的代码,但我想用两个按钮“preview”和“next”替换它们
代码是:
$results = mysqli_query($connecDB,"SELECT COUNT(*) FROM list");
$get_total_rows = mysqli_fetch_array($results); //total records
//break total records into pages
$pages = ceil($get_total_rows[0]/$item_per_page);
//create pagination
if($pages > 1)
{
$pagination = '';
$pagination .= '<ul class="paginate">';
for($i = 1; $i<$pages; $i++)
{
$pagination .= '<li><a href="#" class="paginate_click" id="'.$i.'-page">'.$i.'</a></li>';
}
$pagination .= '</ul>';
}
答案 0 :(得分:1)
您需要一个var来了解当前页面,例如:
$page = ($_GET['page']) ? (int)$_GET['page'] : 1;
if($pages > 1)
{
$pagination = '';
$pagination .= '<ul class="paginate">';
$pagination .= '<li><a href="file.php?page='.($page-1).'" class="paginate_click" id="prev-page">previous</a></li>';
for($i = 1; $i<$pages; $i++)
{
$pagination .= '<li><a href="#" class="paginate_click" id="'.$i.'-page">'.$i.'</a></li>';
}
$pagination .= '<li><a href="file.php?page='.($page+1).'" class="paginate_click" id="next-page">next</a></li>';
$pagination .= '</ul>';
}
答案 1 :(得分:1)
我会使用当前页面使用php get,但如果你正在进行javascript正在进行中这里的页面就是一个例子。
你必须修改,因为我看不到你正在使用的javascript
您可以使用jquery
<?php
$results = mysqli_query($connecDB,"SELECT COUNT(*) FROM list");
$get_total_rows = mysqli_fetch_array($results); //total records
//break total records into pages
$pages = ceil($get_total_rows[0]/$item_per_page);
?>
<ul class="paginate">
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script type="text/javascript">
$(function() {
var hash = $(location).attr('hash');
hash = hash.substring(1, hash.length); // Remove #
var pages = <?php echo $pages; ?>;
var content = '';
if(hash > 1 && hash <= pages)
content += '<li><a href="http://test.com/index.php#' + (hash - 1) + '" class="paginate_click" id="' + (hash - 1) + '-page">previous</a></li>';
if(hash >= 1 && hash < pages)
content += '<li><a href="http://test.com/index.php#' + (hash + 1) + '" class="paginate_click" id="' + (hash + 1) + '-page">next</a></li>';
$('.paginate').html(content);
});
</script>
</ul>