Php“预览”和“下一步”


Php “preview” and “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>';
}
你需要

一个变量来知道当前页面,比如:

$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>';
}

我会将当前页面与 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>