Xiaobai's brief introduction to the use of laypage paging
I am a novice, so I used to use the built-in paging. Later, a master recommended this to me. It felt good, so I recommended it. Paging generally uses GET to pass values, so once you want to perform a search, , you need to add the search value to the URL, otherwise you will click on the next page and the search conditions will be erased. This is your first post. (Welcome experts to give me some suggestions for improvement). It is mainly written for fellow novices who are struggling. Friends, watch it (encourage each other).
//这里是前端页面需要引入的文件,去 http://laypage.layui.com/ 官网下载放在项目下即可(我将文件放在了Public下,然后再调用出来),<script src="/Public/laypage/laypage.js"></script>
//好像很实用的样子,后端的同学再也不用写分页逻辑了。这里只要复制进来就可以了。不用改<b><script></b><br>
<b>laypage({<br>
cont: 'page11',<br>
pages: 18,</b> //假设我们获取到的是18(后端计算完总页数后将总页数值传过来,放在这里即可(类似{$totalpage})).<br>
<b>curr: function(){ </b>//通过url获取当前页,也可以同上(pages)方式获取<br>
<b> var page = location.search.match(/page=(\d+)/);<br>
return page ? page[1] : 1;//如果没有页数显示时,默认是第一页<br>
}(), </b><br>
<b> jump: function(e, first){ </b>//触发分页后的回调<br>
<b> if(!first){</b> //一定要加此判断,否则初始时会无限刷新<br>
<b> location.href=setParam("page",e.curr);<br>
}<br>
}<br>
});</b>
//设置url中连接符(为什么要加这段呢?因为我们要带搜索条件时,一般的URL要带"?","&",这两个符号,这里就是为了,在追加页码时,当有了“?”符号时,会换成“&”,没有时则是“?”加page=页数,以下也是直接复制进去就可以了。)<b>function setParam(param,value){<br>
var query = location.search.substring(1);<br>
var p = new RegExp("(^|)" + param + "=([^&]*)(|$)");<br>
if(p.test(query)){<br>
//query = query.replace(p,"$1="+value);<br>
var firstParam=query.split(param)[0];<br>
var secondParam=query.split(param)[1];<br>
if(secondParam.indexOf("&")>-1){<br>
var lastPraam=secondParam.split("&")[1];<br>
return '?'+firstParam+'&'+param+'='+value+'&'+lastPraam;<br>
}else{<br>
if(firstParam){<br>
return '?'+firstParam+''+param+'='+value;<br>
}else{<br>
return '?'+param+'='+value;<br>
}<br>
}<br>
}else{<br>
if(query == ''){<br>
return '?'+param+'='+value;<br>
}else{<br>
return '?'+query+'&'+param+'='+value;<br>
}<br>
} <br>
}<br>
</script></b>
//最后在你显示数据(例如后)最后添加下面这个<b><div style="margin-top:15px; text-align:center;" id="page11"></div></b>
//The above id is set by yourself. If you change it, pay attention to the previous cont: 'page11', which also needs to be changed here. The preparations for the front end are now complete.
If the search terms also need to include a URL address, here’s what I wrote
//Click to search<b>$("#sou").bind("click",function(event){<br>
Event.preventDefault();</b>//If you don’t understand here, you can check it yourself (the default behavior for canceling events is usually when there is <from>, if not, just remove it directly). <br>
<b>var type=$("#type").val();</b>//Get the hypothetical search condition value<br>
<b>var url=$(this).attr("souid");</b>//Here is the address to jump to when clicking (for example: souid="<*:U('Custom/customorder')*> ;" Change the jump address yourself)<br />
<b> window.location.href=url+"?typeid="+type;<br />
});</b>
(Novices can only write like this, sorry, basic JQ should still be understandable!)
two. Now comes the backend part<b>public function text(){</b><br />
//The following is to get the page number sent by GET. If there is no page number, the page number is 1.<br />
<b>$nowpage=I('page',1);</b><br />
//$totalpage is to calculate the maximum number of pages you want to obtain, ceil is rounded forward, here it is set to 10 pieces of data as 1 page (note the brackets). <br />
<b>$totalpage=ceil((M('order')->where(condition)<br>
->count())/10);//This is as abbreviated as possible. <br>
//Below, please add the sentence limit(($nowpage-1)*10,10), which means the data controls the number of data displayed on each page. After obtaining the number of pages, multiply it by the set number of data to obtain 10 items on the page. (Set it yourself) data<br>
<b>$res=M('order')->where(condition)<br>
->limit(($nowpage-1)*10,10)<br>
->select();</b><br>
//Finally, the data and the maximum number of pages are passed to the front end and accepted. (Search conditions must also be sent if required.) <br>
<b> $this->assign("totalpage",$totalpage);<br>
$this->assign("res",$res);</b><br>
<b>}</b>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Learn about Python programming with introductory code examples Python is an easy-to-learn, yet powerful programming language. For beginners, it is very important to understand the introductory code examples of Python programming. This article will provide you with some concrete code examples to help you get started quickly. Print HelloWorldprint("HelloWorld") This is the simplest code example in Python. The print() function is used to output the specified content

PHP variables store values during program runtime and are crucial for building dynamic and interactive WEB applications. This article takes an in-depth look at PHP variables and shows them in action with 10 real-life examples. 1. Store user input $username=$_POST["username"];$passWord=$_POST["password"]; This example extracts the username and password from the form submission and stores them in variables for further processing. 2. Set the configuration value $database_host="localhost";$database_username="username";$database_pa

The simplest code example of Java bubble sort Bubble sort is a common sorting algorithm. Its basic idea is to gradually adjust the sequence to be sorted into an ordered sequence through the comparison and exchange of adjacent elements. Here is a simple Java code example that demonstrates how to implement bubble sort: publicclassBubbleSort{publicstaticvoidbubbleSort(int[]arr){int

Title: From Beginner to Mastery: Code Implementation of Commonly Used Data Structures in Go Language Data structures play a vital role in programming and are the basis of programming. In the Go language, there are many commonly used data structures, and mastering the implementation of these data structures is crucial to becoming a good programmer. This article will introduce the commonly used data structures in the Go language and give corresponding code examples to help readers from getting started to becoming proficient in these data structures. 1. Array Array is a basic data structure, a group of the same type

"Go Language Programming Examples: Code Examples in Web Development" With the rapid development of the Internet, Web development has become an indispensable part of various industries. As a programming language with powerful functions and superior performance, Go language is increasingly favored by developers in web development. This article will introduce how to use Go language for Web development through specific code examples, so that readers can better understand and use Go language to build their own Web applications. 1. Simple HTTP Server First, let’s start with a

How to use PHP to write the inventory management function code in the inventory management system. Inventory management is an indispensable part of many enterprises. For companies with multiple warehouses, the inventory management function is particularly important. By properly managing and tracking inventory, companies can allocate inventory between different warehouses, optimize operating costs, and improve collaboration efficiency. This article will introduce how to use PHP to write code for inventory warehouse management functions, and provide you with relevant code examples. 1. Establish the database before starting to write the code for the inventory warehouse management function.

Java Selection Sorting Method Code Writing Guide and Examples Selection sorting is a simple and intuitive sorting algorithm. The idea is to select the smallest (or largest) element from the unsorted elements each time and exchange it until all elements are sorted. This article will provide a code writing guide for selection sorting, and attach specific Java sample code. Algorithm Principle The basic principle of selection sort is to divide the array to be sorted into two parts, sorted and unsorted. Each time, the smallest (or largest) element is selected from the unsorted part and placed at the end of the sorted part. Repeat the above

Huawei Cloud Edge Computing Interconnection Guide: Java Code Samples to Quickly Implement Interfaces With the rapid development of IoT technology and the rise of edge computing, more and more enterprises are beginning to pay attention to the application of edge computing. Huawei Cloud provides edge computing services, providing enterprises with highly reliable computing resources and a convenient development environment, making edge computing applications easier to implement. This article will introduce how to quickly implement the Huawei Cloud edge computing interface through Java code. First, we need to prepare the development environment. Make sure you have the Java Development Kit installed (
