Table of Contents
Related query examples in ThinkPHP, ThinkPHP related examples
Home Backend Development PHP Tutorial Related query examples in ThinkPHP, ThinkPHP related examples_PHP tutorial

Related query examples in ThinkPHP, ThinkPHP related examples_PHP tutorial

Jul 13, 2016 am 10:12 AM
thinkphp Inquire

The examples in this article describe the usage of related queries in ThinkPHP. Share it with everyone for your reference. The specific analysis is as follows:

In THINKPHP, associated queries (multi-table queries) can use the table() method or the join method, as shown in the following example:

1. table()

Copy code The code is as follows:
$list = $user->table('user_status stats, user_profile profile')-> where('stats.id = profile.typeid')->field('stats.id as id, stats.display as display, profile.title as title,profile.content as content')->order('stats .id desc' )->select();

2. join()
Copy code The code is as follows:
$user = new Model('user');
$list = $user->join('RIGHT JOIN user_profile ON user_stats.id = user_profile.typeid' )->select();

3. Native query
Copy code The code is as follows:
$Model = new Model();
$sql = 'select a.id,a.title,b.content from think_test1 as a, think_test2 as b where a.id=b.id '.$map.' order by a.id '.$sort.' limit '.$p->firstRow.','.$p->listRows;
$voList = $Model->query($sql);

4. Multi-table query
Copy code The code is as follows:
$Model->field('user.name,role.title')->table ('think_user user,think_role role')->limit(10)->select();

Or:
Copy code The code is as follows:
$Model->field('user.name,role.title')->table(array( 'think_user'=>'user','think_role'=>'role'))->limit(10)->select();

I hope this article will be helpful to everyone’s PHP programming based on the ThinkPHP framework.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/920604.htmlTechArticleExamples of associated queries in ThinkPHP, Examples of associated queries in ThinkPHP This article describes the usage of associated queries in ThinkPHP. Share it with everyone for your reference. The specific analysis is as follows: Related in THINKPHP...
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 Article Tags

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)

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 your academic qualifications on Xuexin.com

How to run thinkphp project How to run thinkphp project Apr 09, 2024 pm 05:33 PM

How to run thinkphp project

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

12306 How to check historical ticket purchase records How to check historical ticket purchase records

There are several versions of thinkphp There are several versions of thinkphp Apr 09, 2024 pm 06:09 PM

There are several versions of thinkphp

How to run thinkphp How to run thinkphp Apr 09, 2024 pm 05:39 PM

How to run thinkphp

How to install thinkphp How to install thinkphp Apr 09, 2024 pm 05:42 PM

How to install thinkphp

Which one is better, laravel or thinkphp? Which one is better, laravel or thinkphp? Apr 09, 2024 pm 03:18 PM

Which one is better, laravel or thinkphp?

How to check the activation date on Apple mobile phone How to check the activation date on Apple mobile phone Mar 08, 2024 pm 04:07 PM

How to check the activation date on Apple mobile phone

See all articles