当前位置:网站首页>PHP can load different new data methods for each refresh
PHP can load different new data methods for each refresh
2022-06-12 10:30:00 【P P PHP】
There's a lot of app, Each time you refresh, new content will be loaded , It's like never finishing painting . Instead of turning the page as we usually do , According to section 1,2,3 Page load data like this , I think of a way , For reference only .
$page = $_GET['page']?:1;
$uniqueNo = str_replace(".","_",getIp())."_".getDeviceid;// Generate a unique user id
if ($page == 1){
cache("loadPage_".$cate."_".$uniqueNo,null);// If it's the first page , Empty the loaded page number cache ,$cate Indicates the parameters required for list query , Generate a loaded page number cache for a specific conditional query
}
$loadPage = cache("loadPage_".$cate."_".$uniqueNo)?:[];// Take out the loaded page number Is an array
$count = Db::name(tablename)->where($where)->cache(1800)->count();// Query the total amount of qualified data
$limit = 10;
$totalPage = ceil($count/$limit);// Calculate the total number of pages
$page = getRandPage($totalPage,$loadPage,$page);
if(!$page){// This indicates that the data has been loaded
$list = [];
}else{
// Normal business processing
$start = ($page-1)*$limit;
$list = Db::name(tablename)->where($where)->limit($start,$limit)->select();
.
.
.
// Add the current page number to the loaded page number cache
array_push($loadPage,$page);
cache("loadPage_".$cate."_".$uniqueNo,$loadPage,1800);
}
/**
* @param $totalPage Total number of pages
* @param $usedPage Loaded page number array
* @param int $isFirst Is it the first page
* @return bool|int
*/
function getRandPage($totalPage,$usedPage,$isFirst = 1){
// If only 1 page
if($totalPage == 1 && $isFirst==1){
return 1;
}
// If the available page numbers have been taken , return false, Description data has ended
if(count($usedPage) >= $totalPage){
return false;
}
// If it is the first time to turn the page , Remove the last page Prevent users from getting the last page number when loading for the first time , And the data volume of the last page is less than one page ( Such as :10 strip ) The situation of , The subsequent pages cannot be turned
if($isFirst == 1){
$randPage = rand(1,$totalPage-1);
}else{
$randPage = rand(1,$totalPage);
}
if(!in_array($randPage,$usedPage)){
return $randPage;
}else{
return getRandPage($totalPage,$usedPage,$isFirst);
}
}The above method also has a drawback , When the user turns many pages , There will be many elements in the loaded page number cache array , In the use of getRandPage Function to get random unused page numbers , Randomly generated page numbers may be stored in the loaded page number cache array , So you have to recycle once , Multiple cycles can cause some time-consuming problems .
边栏推荐
- Global and local existence of array, integer and character variables
- Simple use of autojs
- Mobile terminal commissioning
- PHP curl function
- Leetcdoe 2037. 使每位学生都有座位的最少移动次数(可以,一次过)
- [MySQL] index invalidation and index optimization
- Summary method of lamp environment deployment
- CONDA install tensorflow test tensorflow
- Introduction to IOT
- JS string combination
猜你喜欢

A snare - Cookie spoofing

np. Meshgrid() function and coordinate position generation in 3D space and numpy Introduction to repeat() function

【实验】MySQL主从复制及读写分离

ASP.NET Core权限系统实战(零)

How to play the 2022 Taobao 618 Super Cat Games? What are the strategies for the Super Cat Games

How high can C language reach by self-study alone?

2022淘宝618超级喵运会玩法攻略 618超级喵运会玩法技巧

【机器学习】基于鸢尾花(iris)数据集的逻辑回归分类实践
![[experiment] MySQL master-slave replication and read-write separation](/img/aa/7d0799013ff749cacf44ba3b773dff.png)
[experiment] MySQL master-slave replication and read-write separation

Love and hate in the Jianghu
随机推荐
Oculus quest generation opens Bluetooth connection
[SQLite3] memory debugging
2022淘宝618超级喵运会玩法攻略 618超级喵运会玩法技巧
ID obfuscation
CONDA install tensorflow test tensorflow
【机器学习】基于鸢尾花(iris)数据集的逻辑回归分类实践
93. 获得内网的所有IP地址
Download Notepad++
The solution of Lenovo notebook ThinkPad t440 WiFi dropping all the time
Leetcdoe 2037. 使每位学生都有座位的最少移动次数(可以,一次过)
Halcon combined with C # to detect surface defects -- affine transformation (III)
[MySQL] index invalidation and index optimization
Mobile terminal commissioning
Circuitbreaker fuse of resilience4j -- Measurement of circuitbreakermetrics index
Jump to wechat in app and open wechat
IIS add MIME type
The solution of Lenovo notebook ThinkPad t440 WiFi unable to connect to the Internet
JS string combination
2022京东618预售定金怎么退?京东618定金能退吗?
Raw socket usage