当前位置:网站首页>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;
}边栏推荐
- CTF PHP audit bypasses filtering learning from topics
- Tp6 controller does not exist: app\index\controller\index
- Report on operation mode and future development trend of China's refining and chemical market 2022-2028
- Development trend and prospect forecast report of China's financial industry 2022-2028 Edition
- SQL related knowledge - DQL
- Zhubo Huangyu: all the precious metals you want to know are here
- 捕获数据包(Wireshark)
- Go SQL parsing time Time type
- Unity移动端游戏性能优化简谱之 以引擎模块为划分的CPU耗时调优
- 1064 (42000) error occurred when installing MySQL and modifying root password
猜你喜欢
![[QT] resource file import](/img/0f/6eff57a09edda284b833947dab16af.png)
[QT] resource file import

Your requirements could not be resolved

MySQL index details
![ctf [RoarCTF 2019]easy_ calc](/img/c7/16adb8e4b64a4be2129a6c53c5aaa7.jpg)
ctf [RoarCTF 2019]easy_ calc

Mysql8.0 configuring my SQL in INI file_ mode=NO_ AUTO_ CREATE_ User can start

After four years of outsourcing, people are directly abandoned...

Verrouillage de lecture et d'écriture pour la synchronisation des fils

Clickhouse stand alone installation

Group by and order by are used together

35岁程序员炒Luna 千万资产3天归零,网友:和赌博一样
随机推荐
钉钉开放平台-小程序开发实战(钉钉小程序客户端)
Principle and implementation of syn cookie
Go SQL parsing time Time type
mysql自带的性能测试工具mysqlslap执行压力测试
Syntax error of go language generic in IDE
Conditional variables for thread synchronization
Install cenos in the virtual machine
Part 4: drawing quadrilateral
小程序中实现视频通话及互动直播功能
Group by and order by are used together
MySQL enable logbin in Qunhui docker
MySQL est livré avec l'outil de test de performance MySQL lap pour effectuer des tests de résistance
【QT】对话框dialog
Lua语法讲解
2021 year end summary
Knowledge of functions
[Qunhui] import certificate
捕获数据包(Wireshark)
35岁程序员炒Luna 千万资产3天归零,网友:和赌博一样
In 2022, what professional competitions can college students majoring in automation, electrical engineering and automation participate in?