java - What is a more elegant way to implement paging loading in business?
阿神
阿神 2017-06-06 09:51:51
0
6
614

As part of the project responsible for the school's library in the next semester, I now encounter a business design difficulty.

For example, on the homepage, I plan to use ajax to load all the information when students query related information. I am not used to many websites such as Zhihu that drag to the bottom to load automatically. My idea is to set up a paging option at the bottom, display 15 records on each page, and load all articles using ajax.

The sql statement is probably select xxx from xxx condition limit 15 offset xxx. But now because I want to do paging, I must know how many records a student has in the database in order to design the front end. The total records can be queried through the SQL statement select count(*) from xxx condition. The total records are then saved in the frontend.

If this is the case, the query must be split into two sql statements, which does not feel very elegant. Is there any more elegant implementation plan?

ps: Because there are many similar businesses in the system that require similar paging designs, it is too inelegant to use two SQL statements to query separately every time.

Replenish

The respondent seems that didn’t even read the question. One person answered about sql statement 1, and the other person talked about the front end.

Thank you all for your answers. The problem has been solved. It seems that only two sql statements can be used ^_^

阿神
阿神

闭关修行中......

reply all(6)
大家讲道理
var start = 页标 - 1;
$.get("url?start=" + start * 15,function(){});
$start = $_GET["start"];
$end = $start + 15;
$sql = "select * from table limit {$start}, {$end}"; 
select a.*, b.count from table a, (select count(*) as count from table ) b LIMIT 1,15
仅有的幸福

Don’t think about it, it must be two.
You can also have one:
select * from table
union
select 0, 0...., count(*) from table

刘奇

This is normal. If you want to use a SQL to solve the problem, you have to check all the objects from the database and perform a series of operations, but your memory may explode.

淡淡烟草味

Don’t think about it, it must be two. The implementation of paging defines a generic class page<T> and what is put in it. Do you need me to explain in more detail?

習慣沉默

Try PageHelper, it’s just a sql statement, you don’t even need a limit

过去多啦不再A梦

For elegant paging, there are many plugins for paging

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!