There are two ways to use limit for paging in MySQL
Example 1, suppose that there are 13 data in the database table student.
code example:
Statement 1:select * FROM student limit 9,4
Statement 2:slect * FROM student limit 4 offset 9
Statements 1 and 2 return rows 10th, 11, 12, and 13 of table student, the first parameter represents the beginning of the next data in the parameter, and the second parameter represents the number of data bars returned each time.
4 in Statement 2 returns 4 rows, 9 means starting from row tenth of the table
Example 2, the paging function can be achieved by limit and offset or by limit only.
Assuming that pagesize represents the number of bars to display per page, pagenumber represents the page number, then return to page pagenumber, the SQL statement with the number of pagesize per page:
code example:
Statement 3:select * FROM studnet limit (pageNumber-1) *pagesize,pagesize
Statement 4:select * FROM student limit pageSize offset (pageNumber-1) *pagesize
Calculate pagesize and offset in Java
The number of bars displayed per page, as an interface parameter passed in
int pageSize = 10;
Total number of bars, querying from the database
int totalcount;
//Total pages Double tp= count/(double) pageSize; int totalpage = (int) Math.ceil (TP); int offset = (page-1) * pageSize;
MySQL Limit paging