简体   繁体   English

如何在分页控件中结合使用PHP和jQuery

[英]How can I combine PHP and jQuery in paging controls

I am trying to implement paging in PHP. 我正在尝试在PHP中实现分页。 First of all I am getting the number of pages as per page record and generating <li> links dynamically by number of pages. 首先,我要获取每个页面记录的页面数,并按页面数动态生成<li>链接。 Like this: 像这样:

for($i = 1; $i <= $no_of_pages; $i++)
{
    echo '<li><a href="view_records.php?pageno='.$i.'">'.$i.'</a></li>';
}

It's fine, but the problem is that when the number of pages is more than 10, the page number wraps to the next line. 很好,但是问题是当页数大于10时,页码将换行到下一行。 I want to scroll them by clicking left and right 10 pages each time. 我想通过每次单击左右10页来滚动它们。

Suppose I have 35 pages, so this will display all 35 pages links 假设我有35页,那么这将显示所有35页的链接

left 1 2 3 4 5 6 7 8 9 10 11 12 ......35 right

But I want only 但我只想要

left 1 2 3 4 5 6 7 8 9 10 right 

When I click on right this will scroll right and should display 当我单击right它将向右滚动并显示

left 11 12 13 14 15 17 18 19 20 right

Again right will display next 10 pages link. 再次right将显示接下来的10页链接。 Is there anything in JS or jQuery to control that li for scrolling? JS或jQuery中有什么可以控制该li的滚动吗? It will be become easy because I get total no of pages by PHP and put link of them in HTML and user can directly move to desired page. 这将变得很容易,因为我通过PHP获得的页面总数不多,并将它们的链接放到HTML中,用户可以直接移动到所需的页面。

It's too late for the answer. 答案为时已晚。 Anyway, you can initially get the first 10 page links in the page right. 无论如何,您最初可以在页面右侧获得前10个页面链接。 Then you can use jQuery to change content inside parent element of li tags (its ul). 然后,您可以使用jQuery更改li标签(其ul)的父元素内的内容。 When you click on 'right', empty the content of ul element. 当您单击“右”时,请清空ul元素的内容。 Append new li elements using a loop to generate. 使用循环附加新的li元素来生成。 You may need a hidden value to control the page limits. 您可能需要一个隐藏值来控制页面限制。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM