分页问题 - 尚未成功

发布于 2024-09-25 05:52:53 字数 464 浏览 0 评论 0原文

嘿伙计们,我真的把这件事搞砸了。

这就是我正在做的:如果有 100 个用户要从数据库中获取,我将使用分页并一次显示 10 个用户。当用户点击下一页时,他将通过ajax(称为点击时ajax)获取接下来的10个用户,依此类推。我现在显示 10 个页面链接,其中包括第一个、下一个、最后一个和上一个链接。

流程如下:在 a.php 上创建链接并为每个链接调用 ajax 函数,传递 url(b.php) &目标(我将在其中获得结果),其中 url 还传递单击的页号。,此页号。将转到 b.php,接下来的 10 个用户将在 ajax 的帮助下显示。

这就是问题所在:目前我显示 1-10 个链接,其中包含第一个和最后一个链接,无法显示下一个和上一个链接,因为要重定向到下一个或上一个,我没有在 a.php 上获取当前页码,即 i'我传递给 b.php。还在 foreach 循环中创建链接。 我正在努力完成这件事,但还没有成功。

等待有价值的回复。

Hey guys I am really messing up with this.

This is I'm doing: If there are 100 users to fetch from Database, I'm using pagination and showing 10 users at a time. when user will click on next page, he will get next 10 users through ajax(called ajax on click) and so on. I'm showing 10 page-links right now with first, next last and previous links.

This is how flow will go: On a.php created links and called ajax function with every link, passing url(b.php) & target(where I will get result), with url also passing clicked pageno., this pageno. will go to b.php and next 10 users will be shown with the help of ajax.

This is the problem: Currently I'm showing 1-10 links with first and last links, unable to show next and previous links because to redirect to next or previous, I am not getting the current page number on a.php i.e i'm passing to b.php. also links are created in foreach loop.
I am trying hard to get this done, but no success yet.

waiting for valuable reply.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

满栀 2024-10-02 05:52:53

好吧,我认为我明白了...

我认为您需要做的是将当前页码存储为 JavaScript 变量。使用执行 Ajax 的函数来更新此变量并更新下一个/上一个链接。

希望这有帮助。

更新:
再想一想,这是一个更好的主意。直接在链接中调用 ajax 意味着您必须组合一个 url 并更新它,这既尴尬又烦人。这并不理想。相反,最好存储变量并让一些设置函数以设置的方式使用它们。因此,您可以这样做:

<a href="javascript:void(0)" onclick="gotoNextPage()">

而不是向它们传递要访问的页面编号,您可以将当前页码存储在 javascript 变量中并执行如下操作:

gotoNextPage(){
    // lets assume the current page number is stored in a 
    // variable defined outside of this function called curr_page
    curr_page++; // increment the current
    call_ajax('user_info.php?pageno='+curr_page);
}

这样链接的代码就不会改变。

您仍然可以将其他变量(例如“order”、“perpage”等)传递给 gotoNextPage(),但您可能会发现不需要这样做。

需要记住以下几点:
1. 使用 jQuery 或类似的东西可能会让你的事情变得更容易。
2. 任何未启用 javascript 的人将无法使用您的网站。考虑将其更改为类似

<?php
    echo '<a href="your_main_page.php?page_number=', ($curr_page + 1), '" onclick="gotoNextPage()">';
?>

这样的方式,它可以通过 ajax 方法工作,但对于没有 javascript 的人也可以工作(如果不是那么顺利并且需要重新加载页面)。不过,这对您来说需要做更多的工作...所以这是您的选择!

希望这是有道理的。这是漫长的一天!

Ok, I think I understand...

I think what you need to do is store the current page number as a JavaScript variable. Use the function that is doing the Ajax to update this variable and also update the next/previous links.

Hope this helps.

Update:
On second thoughts, here's a better idea. Having your ajax call directly in your link means you have to put together a url and update it, which is awkward and annoying. This isn't ideal. Instead it is better to store the variables and have some set functions work with them in a set way. So, you could have something like:

<a href="javascript:void(0)" onclick="gotoNextPage()">

Rather than passing them the number of the page to go to, you can store the current page number in a javascript variable and do something like this:

gotoNextPage(){
    // lets assume the current page number is stored in a 
    // variable defined outside of this function called curr_page
    curr_page++; // increment the current
    call_ajax('user_info.php?pageno='+curr_page);
}

This way the code for the link doesn't ever change.

You can still pass other variables (such as 'order', 'perpage' etc) to gotoNextPage() but you might find you don't need to.

A couple of things to bear in mind:
1. Using jQuery or something similar would probably make things easier for you.
2. Anyone without javascript enabled will not be able to use your site. Consider changing it to something like

<?php
    echo '<a href="your_main_page.php?page_number=', ($curr_page + 1), '" onclick="gotoNextPage()">';
?>

This way it would work for via the ajax method but would also work (if not as smoothly and with a page reload) for people without javascript. It's a bit more work for you though...so hat's your choice!

Hope this makes sense. It's been a long day!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文