当前位置:网站首页>TP5 distinct method paging problem
TP5 distinct method paging problem
2022-06-26 04:20:00 【Telkobe】
DISTINCT Method to return a unique different value , and tp In the use of DISTINCT There are some problems with paging when using the , The total number of paging statistics is inconsistent with the total number of queries, resulting in paging exceptions , The following is for tp5 A few small changes have been made to deal with this problem
First of all, I'll go to Query.php Of paginate Method , And then follow the path



echo Output $aggregate . '(' . (!empty($distinct) ? 'DISTINCT ' : '') . $field . ') AS tp_' . strtolower($aggregate)

There is basically no need to look down , Then there is assembly sql Carry out these . Finding this step is easy , Try to put COUNT(*) AS tp_count Just change it to what we want , such as COUNT(DISTINCT xxx) AS tp_count,DISTINCT Must be followed by the field name , You can't just write one *, Will report a mistake , Such as COUNT(DISTINCT user_name) AS tp_count; In order to minimize the impact on the framework itself , So a new function is added to handle , Here is the code .



/**
* @param $str Field name , Such as user_name a.user_name
* @return $this
*/
public function distinct_count($str){
$this->options['distinct_count'] = $str;
return $this;
}
/**
* Aggregate query
* @access public
* @param string $aggregate Polymerization methods
* @param string $field Field name
* @param bool $force Force to numeric type
* @return mixed
*/
public function aggregate($aggregate, $field, $force = false)
{
if (0 === stripos($field, 'DISTINCT ')) {
list($distinct, $field) = explode(' ', $field);
}
if (!preg_match('/^[\w\.\+\-\*]+$/', $field)) {
throw new Exception('not support data:' . $field);
}
if(strlen($this->options['distinct_count'] ?? '')){
$result = $this->value($aggregate . '(DISTINCT '.$this->options['distinct_count'].') AS tp_' . strtolower($aggregate), 0, $force);
}else{
$result = $this->value($aggregate . '(' . (!empty($distinct) ? 'DISTINCT ' : '') . $field . ') AS tp_' . strtolower($aggregate), 0, $force);
}
return $result;
}边栏推荐
- Etcd watch principle
- Redis cache data consistency solution analysis
- The stc-isp burning program for 51 single chip microcomputer always shows that "the target single chip microcomputer is being detected..." the cold start board does not respond
- Judge the same value of two sets 𞓜 different values
- Syntax error of go language generic in IDE
- 35岁程序员炒Luna 千万资产3天归零,网友:和赌博一样
- [从零开始学习FPGA编程-45]:视野篇 - 集成电路助力数字化时代高质量发展-2-市场预测
- Development trend and prospect forecast report of China's financial industry 2022-2028 Edition
- Lua语法讲解
- MySQL enable logbin in Qunhui docker
猜你喜欢

Threejs专用天空盒素材,五种天空盒素材免费下载

Gateway can not connect to tcp://127.0.0.1: Connection refused

Chrome page recording and playback function

Matplotlib line chart, text display, win10

35岁程序员炒Luna 千万资产3天归零,网友:和赌博一样

Clickhouse stand alone installation
![[QT] dialog box](/img/ca/e65a0c167a4509f7c6a241870f6a32.png)
[QT] dialog box

Threejs special sky box materials, five kinds of sky box materials are downloaded for free

College C language final exam · multiple choice questions · summary notes of mistakes and difficulties

pip 批量完全卸载包
随机推荐
Development prospect and investment strategic planning report of global and Chinese PVC hose industry from 2022 to 2028
SQL related knowledge - DQL
Sorting out the knowledge points of the renderview renderobject parentdata of the shuttle
Report on operation mode and future development trend of China's refining and chemical market 2022-2028
Question brushing record day01
CTF PHP audit bypasses filtering learning from topics
After a test of 25K bytes, I really saw the basic ceiling
35岁程序员炒Luna 千万资产3天归零,网友:和赌博一样
线程同步之条件变量
Tp6 multi table Association (table a is associated with table B, table B is associated with table C, and table d)
What should I do if the 51 SCM board cannot find the device in keil
win10 系统打开的软件太小,如何变大(亲测有效)
1. foundation closing
Your requirements could not be resolved
Minecraft 1.16.5 biochemical 8 module 1.9 version 1.18 version synchronization
修改Oracle连接数
Threejs专用天空盒素材,五种天空盒素材免费下载
六、项目实战---识别猫和狗
NFT creation and binding of BSC and HT chains
2021 year end summary