我写了一个函数,允许我进行分页。问题来了:当我单击按钮将页面更改为 URL 时,会添加许多相同的值,如下所示:
时事通讯.php?action=sent-emails&page=2&page=1&page=4&page=5&page=7&page=5&page=1
function pagination($sql_general,$page_name_pagination,$page_query_pagination) {
require $_SERVER['DOCUMENT_ROOT'] . 'it/intranet/includes/dbh.inc.php';
$sql1 = $sql_general;
$sql1_query = mysqli_query($conn, $sql1);
$total = mysqli_num_rows($sql1_query);
$adjacents = 3;
$targetpage = $page_name_pagination; //your file name
if (!empty($page_query_pagination)) {
$targetpage .= "?" . $page_query_pagination . "&page=";
} else {
$targetpage .= "?page=";
}
$limit = 10; //how many items to show per page
$page = $_GET['page'];
if($page){
$start = ($page - 1) * $limit; //first item to display on this page
}else{
$start = 0;
}
/* Setup page vars for display. */
if ($page == 0) $page = 1; //if no page var is given, default to 1.
$prev = $page - 1; //previous page is current page - 1
$next = $page + 1; //next page is current page + 1
$lastpage = ceil($total/$limit); //lastpage.
$lpm1 = $lastpage - 1; //last page minus 1
$pagination = "";
if($lastpage > 1)
{
$pagination .= "<div class='pagination1'> <ul class='pagination'>";
if ($page > $counter+1) {
$pagination.= "<li class='page-item'><a class='page-link' href=\"$targetpage$prev\"><</a></li>";
}
if ($lastpage < 7 + ($adjacents * 2))
{
for ($counter = 1; $counter <= $lastpage; $counter++)
{
if ($counter == $page)
$pagination.= "<li class='page-item'><a class='page-link' href='#' >$counter</a></li>";
else
$pagination.= "<li class='page-item'><a class='page-link' href=\"$targetpage$counter\">$counter</a></li>";
}
}
elseif($lastpage > 5 + ($adjacents * 2)) //enough pages to hide some
{
现在,如何检查“page=x”是否存在并替换该值?
暮色呼如