Home Backend Development PHP Tutorial 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

Jul 03, 2018 pm 04:32 PM
cakephp Pagination Inquire

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!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

CakePHP Working with Database CakePHP Working with Database Sep 10, 2024 pm 05:25 PM

Working with database in CakePHP is very easy. We will understand the CRUD (Create, Read, Update, Delete) operations in this chapter.

12306 How to check historical ticket purchase records How to check historical ticket purchase records 12306 How to check historical ticket purchase records How to check historical ticket purchase records Mar 28, 2024 pm 03:11 PM

Download the latest version of 12306 ticket booking app. It is a travel ticket purchasing software that everyone is very satisfied with. It is very convenient to go wherever you want. There are many ticket sources provided in the software. You only need to pass real-name authentication to purchase tickets online. All users You can easily buy travel tickets and air tickets and enjoy different discounts. You can also start booking reservations in advance to grab tickets. You can book hotels or special car transfers. With it, you can go where you want to go and buy tickets with one click. Traveling is simpler and more convenient, making everyone's travel experience more comfortable. Now the editor details it online Provides 12306 users with a way to view historical ticket purchase records. 1. Open Railway 12306, click My in the lower right corner, and click My Order 2. Click Paid on the order page. 3. On the paid page

How to check your academic qualifications on Xuexin.com How to check your academic qualifications on Xuexin.com Mar 28, 2024 pm 04:31 PM

How to check my academic qualifications on Xuexin.com? You can check your academic qualifications on Xuexin.com, but many users don’t know how to check their academic qualifications on Xuexin.com. Next, the editor brings you a graphic tutorial on how to check your academic qualifications on Xuexin.com. Interested users come and take a look! Xuexin.com usage tutorial: How to check your academic qualifications on Xuexin.com 1. Xuexin.com entrance: https://www.chsi.com.cn/ 2. Website query: Step 1: Click on the Xuexin.com address above to enter the homepage Click [Education Query]; Step 2: On the latest webpage, click [Query] as shown by the arrow in the figure below; Step 3: Then click [Login Academic Credit File] on the new page; Step 4: On the login page Enter the information and click [Login];

CakePHP Creating Validators CakePHP Creating Validators Sep 10, 2024 pm 05:26 PM

Validator can be created by adding the following two lines in the controller.

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

In this chapter, we are going to learn the following topics related to routing ?

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

To work on file upload we are going to use the form helper. Here, is an example for file upload.

See all articles