Home  >  Article  >  Backend Development  >  Introduction to cakephp2.X multi-table joint query join and the method of using paging query

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

不言
不言Original
2018-07-03 16:32:321767browse

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;
}

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);

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!

Statement:
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