Introduction to cakephp2.X multi-table joint query join and the method of using paging query

不言
Release: 2023-04-02 09:22:01
Original
1765 people have browsed it

This article mainly introduces cakephp2. The examples in this article describe cakephp2.X multi-table joint query join and the method of using paging query. Share it with everyone for your reference, the details are as follows:

Formatting parameters:

public function getconditions($data){
  $this->loadModel("Cm.LoginHistory");
  $conditions = array();
  foreach ($data as $key=>$val){
    if($key=='start_date'){
      $conditions['LoginHistory.logintime >=']=trim($val);
    }elseif ($key=='end_date'){
      $conditions[&#39;LoginHistory.logouttime <=&#39;]=trim($val);
    }elseif ($key==&#39;selectvsoftid&#39; and $val !=&#39;&#39;){
      $conditions[&#39;LoginHistory.LOGINSUBSYSTEM LIKE&#39;]=&#39;%&#39;.trim($val).&#39;%&#39;;
    }elseif ($key==&#39;username&#39; and $val !=&#39;&#39;){
      $conditions[&#39;LoginHistory.USERNAME LIKE&#39;]=&#39;%&#39;.trim($val).&#39;%&#39;;
    }elseif ($key==&#39;vdevicename&#39; and $val !=&#39;&#39;){
      $conditions[&#39;LoginHistory.WINDOWNAME LIKE&#39;]=&#39;%&#39;.trim($val).&#39;%&#39;;
    }elseif ($key==&#39;selectvsoftid&#39; and $val !=&#39;&#39;){
      $conditions[&#39;LoginHistory.PHDEVICENAME LIKE&#39;]=&#39;%&#39;.trim($val).&#39;%&#39;;
    }
  }
  return $conditions;
}
Copy after login

Paging query:

$fields = array(&#39;LoginHistory.windowname&#39;,&#39;LoginHistory.loginsubsystem&#39;,&#39;VirtualDevice.PHDEVICEID&#39;,&#39;LoginHistory.userid&#39;, &#39;VirtualDevice.SYSTYPEID&#39;,&#39;UserInfo.USERNAME&#39;,&#39;"SUM"(LoginHistory.LOGOUTTIME-LoginHistory.LOGINTIME) moument&#39;,&#39;UserInfo.USERNAME&#39;,&#39;DeviceInfo.DEVICENAME&#39;);
$group=array(&#39;LoginHistory.windowname&#39;, &#39;LoginHistory.loginsubsystem&#39;, &#39;LoginHistory.userid&#39;,&#39;UserInfo.USERNAME&#39;,&#39;DeviceInfo.DEVICENAME&#39;,&#39;VirtualDevice.SYSTYPEID&#39;,&#39;VirtualDevice.PHDEVICEID&#39;);
$this->paginate = array(&#39;conditions&#39;=>$conditions,&#39;fields&#39;=>$fields,&#39;group&#39;=>$group,&#39;limit&#39;=>9,&#39;joins&#39; => array(
   array(
     &#39;alias&#39; => &#39;UserInfo&#39;,
     &#39;table&#39; => &#39;SMM_USERINFO&#39;,
     &#39;type&#39; => &#39;LEFT&#39;,
     &#39;conditions&#39; => &#39; LoginHistory.USERID=UserInfo.USERID &#39;,
   ),
   array(
     &#39;alias&#39; => &#39;VirtualDevice&#39;,
     &#39;table&#39; => &#39;ET_NMVIRTUALDEVICEINFO&#39;,
     &#39;type&#39; => &#39;LEFT&#39;,
     &#39;conditions&#39; => &#39; LoginHistory.WINDOWNAME=VirtualDevice.DEVICENAME &#39;,
   ),
   array(
     &#39;alias&#39; => &#39;DeviceInfo&#39;,
     &#39;table&#39; => &#39;ET_NMDEVICEINFO&#39;,
     &#39;type&#39; => &#39;LEFT&#39;,
     &#39;conditions&#39; => &#39; VirtualDevice.PHDEVICEID=DeviceInfo.DEVICEID &#39;,
   ),
 ));
$LoginHistory = $this->paginate(&#39;LoginHistory&#39;);
$this->set(&#39;loginhistory&#39;,$LoginHistory);
Copy after login

The above is the entire content of this article. I hope it will be helpful to everyone’s study. For more related content, please pay attention to the PHP Chinese website!

Related recommendations:

Introduction to the operation classes and usage of PHP full-featured non-deformation image cropping


ThinkPHP writing array Methods to insert and obtain the latest inserted data ID


The above is the detailed content of Introduction to cakephp2.X multi-table joint query join and the method of using paging query. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
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!