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['LoginHistory.logouttime <=']=trim($val); }elseif ($key=='selectvsoftid' and $val !=''){ $conditions['LoginHistory.LOGINSUBSYSTEM LIKE']='%'.trim($val).'%'; }elseif ($key=='username' and $val !=''){ $conditions['LoginHistory.USERNAME LIKE']='%'.trim($val).'%'; }elseif ($key=='vdevicename' and $val !=''){ $conditions['LoginHistory.WINDOWNAME LIKE']='%'.trim($val).'%'; }elseif ($key=='selectvsoftid' and $val !=''){ $conditions['LoginHistory.PHDEVICENAME LIKE']='%'.trim($val).'%'; } } return $conditions; }
Paging query:
$fields = array('LoginHistory.windowname','LoginHistory.loginsubsystem','VirtualDevice.PHDEVICEID','LoginHistory.userid', 'VirtualDevice.SYSTYPEID','UserInfo.USERNAME','"SUM"(LoginHistory.LOGOUTTIME-LoginHistory.LOGINTIME) moument','UserInfo.USERNAME','DeviceInfo.DEVICENAME'); $group=array('LoginHistory.windowname', 'LoginHistory.loginsubsystem', 'LoginHistory.userid','UserInfo.USERNAME','DeviceInfo.DEVICENAME','VirtualDevice.SYSTYPEID','VirtualDevice.PHDEVICEID'); $this->paginate = array('conditions'=>$conditions,'fields'=>$fields,'group'=>$group,'limit'=>9,'joins' => array( array( 'alias' => 'UserInfo', 'table' => 'SMM_USERINFO', 'type' => 'LEFT', 'conditions' => ' LoginHistory.USERID=UserInfo.USERID ', ), array( 'alias' => 'VirtualDevice', 'table' => 'ET_NMVIRTUALDEVICEINFO', 'type' => 'LEFT', 'conditions' => ' LoginHistory.WINDOWNAME=VirtualDevice.DEVICENAME ', ), array( 'alias' => 'DeviceInfo', 'table' => 'ET_NMDEVICEINFO', 'type' => 'LEFT', 'conditions' => ' VirtualDevice.PHDEVICEID=DeviceInfo.DEVICEID ', ), )); $LoginHistory = $this->paginate('LoginHistory'); $this->set('loginhistory',$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 croppingThinkPHP writing array Methods to insert and obtain the latest inserted data IDThe 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!