gpt4 book ai didi

javascript - 现有代码中的 PHP 分页下一个按钮

转载 作者:行者123 更新时间:2023-12-02 16:47:34 25 4
gpt4 key购买 nike

我一直在关注关于使用 AjaxJQueryPHP 分页的相当深入的教程,我正在尝试修改它这样我就可以在分页选项卡中显示下一个按钮。

这是我用来生成分页栏的代码:

$results = mysqli_query($connecDB,"SELECT COUNT(*) FROM paginate");
$get_total_rows = mysqli_fetch_array($results); //total records
$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 .= '<li><a href="#" class="paginate_click" name="nxt" >>></a></li>';//Next
$pagination .= '</ul>';
}

接下来,我等待文档准备好并运行此脚本:

$(document).ready(function() {
$("#results").load("fetch_pages.php", {'page':0}, function() {
$("#1-page").addClass('active');
});

$(".paginate_click").click(function (e) {
$("#results").prepend('<div class="loading-indication"><img src="ajax-loader.gif" /> Loading...</div>');
var clicked_id = $(this).attr("id").split("-");
var page_num = parseInt(clicked_id[0]);
$('.paginate_click').removeClass('active');
$("#results").load("fetch_pages.php", {'page':(page_num-1)}, function(){
});
$(this).addClass('active');
return false;
});
});

这是html:

<body>
<div id="results"></div>
<?php echo $pagination; ?>
</body>

然后它会输出一个结果列表以及它们下面的分页栏,并且它运行良好。我遇到的问题是如何包含“下一步”按钮?我目前正在研究这个问题,所以我尝试的任何新代码都会发布到这个问题中。将不胜感激任何帮助。

最佳答案

根据您的评论:

首先给出<a>当你在 php 中创建它时一些数据。我假设您知道它们在脚本的这一部分中位于哪个页面

<a href="#" data-currentPageId=".$currentPageId." class="next"></a>

//or just create the next page link based on the id
$nexPage = 'http://nextpagebasedoncurrentpage.php';
<a href="#" data-nextPage=".$nextPage." class="next"></a>

Javascript:

$('.next').click(function(){
current_page_id = $(this).data('currentPageId');
window.location = http://....however you get to the next page based on the id

//or go to the next page if you chose that option
next_page_location = $(this).data('nextPage');
window.location = next_page_location;
});

关于javascript - 现有代码中的 PHP 分页下一个按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26977821/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com