当前位置:网站首页>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 .
边栏推荐
- 2022京东618预售定金怎么退?京东618定金能退吗?
- PHP wechat payment V3 interface
- Composer command
- Add jar package under idea2018 web project
- SAP Hana error message sys_ XSA authentication failed SQLSTATE - 28000
- 使用cpolar远程办公(2)
- MySQL user and permission management, role management
- Win10 professional edition user name modification
- Love and hate in the Jianghu
- [MySQL] learn more about the clustered indexes and auxiliary indexes (b+ tree indexes) in InnoDB
猜你喜欢

CONDA install tensorflow test tensorflow
![Reverse analysis of Huawei housekeeper software [transfer]](/img/85/7af372808e75f8791936c59918466f.jpg)
Reverse analysis of Huawei housekeeper software [transfer]
![[machine learning] practice of logistic regression classification based on Iris data set](/img/c6/0233545d917691b8336f30707e4636.png)
[machine learning] practice of logistic regression classification based on Iris data set
![[CEGUI] resource loading process](/img/52/819843db21549b5e5031258f2c5cb0.jpg)
[CEGUI] resource loading process

Getting started with cloud API basics -- basic knowledge of picgo writing plug-ins

Circuitbreaker fuse of resilience4j - circuitbreakerregistry register

On the improvement of 3dsc by harmonic shape context feature HSC

4. creator mode

MYSQL用户与权限管理,角色管理

Remote desktop cannot copy and paste solution
随机推荐
一测两三年,记测试交流经验的一些感想
How to play the 2022 Taobao 618 Super Cat Games? What are the strategies for the Super Cat Games
Dynamic proxy
[CEGUI] concept introduction
MySQL user and permission management, role management
Qt自定义窗口圆角
[CEGUI] font loading optimization
properties中文乱码
验收标准到底是不是测试用例?
[Wayland] Wayland introduction and customized guidance
Leetcdoe 2037. 使每位学生都有座位的最少移动次数(可以,一次过)
JS obtains the time period of this week and last week (one time period is from Monday to Sunday)
高通平台如何修改特殊电压
Mqtt protocol Chinese version
pycharm 查看opencv当前的版本
conda 安装tensorflow 测试tensorflow
Several methods of importing ThinkPHP
[926. flip the string to monotonic increment]
[machine learning] practice of logistic regression classification based on Iris data set
golang中的定时器