我创建了一个jquery分页但问题是,在我执行编辑或删除分页列表中显示的数据库中的条目之后。分页得到刷新并跳回第一页。我想在页面中执行编辑或删除后回到同一页面。
我在名为list.php
的文件中使用以下代码:
$(document).ready(function () {
$("#results").load("fetch_pages.php"); //initial page number to load
$(".pagination").bootpag({
total: <? php echo $pages; ?> ,
page: 1,
maxVisible: 5
}).on("page", function (e, num) {
e.preventDefault();
$("#results").prepend('<div class="loading-indication"><img src="images/ajax-loader.gif" /> Loading...</div>');
$("#results").load("fetch_pages.php", {
'page': num
});
});
});
并在名为fetch_pages.php
的文件中我使用以下代码:
if(isset($_POST["page"])){
$page_number = filter_var($_POST["page"], FILTER_SANITIZE_NUMBER_INT, FILTER_FLAG_STRIP_HIGH);
if(!is_numeric($page_number)){
die('Invalid page number!');
} //incase of invalid page number
echo "$page_number";
}else{
$page_number = 1;
}
//get current starting point of records
$position = (($page_number-1) * $item_per_page);
$results = mysqli_query($connecDB, "SELECT id, seae, brand, territory, name, e_id, email, contact ,exist FROM employees ORDER BY name ASC LIMIT $position, $item_per_page");
$position
存储定义需要在页面上显示的记录数的值。
任何人都可以帮助我如何回到同一页面而不回到第一页?
答案 0 :(得分:0)
试试这个
$(document).ready(function () {
$("#results").load("fetch_pages.php"); //initial page number to load
$(".pagination").bootpag({
total: <? php echo $pages; ?> ,
page: <?=$_SESSION['position']?$_SESSION['position']:1?>,
maxVisible: 5
}).on("page", function (e, num) {
e.preventDefault();
$("#results").prepend('<div class="loading-indication"><img src="images/ajax-loader.gif" /> Loading...</div>');
$("#results").load("fetch_pages.php", {
'page': num
});
});
});
if(isset($_POST["page"])){
$page_number = filter_var($_POST["page"], FILTER_SANITIZE_NUMBER_INT, FILTER_FLAG_STRIP_HIGH);
if(!is_numeric($page_number)){
die('Invalid page number!');
} //incase of invalid page number
echo "$page_number";
}else{
$page_number = 1;
}
//get current starting point of records
$position = (($page_number-1) * $item_per_page);
$_SESSION['position']=$position;
你需要重置$ _SESSION [&#39; position&#39;]从头开始