Link query instance in ThinkPHP, ThinkPHP link instance _ PHP Tutorial

Source: Internet
Author: User
Link query instances in ThinkPHP, and ThinkPHP associates with instances. Link query instances in ThinkPHP. This article describes the use of link query in ThinkPHP. Share it with you for your reference. The specific analysis is as follows: Associate THINKPHP with the query instance, and ThinkPHP with the instance

This example describes how to use the associated query in ThinkPHP. Share it with you for your reference. The specific analysis is as follows:

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

1. table ()

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

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

The code is as follows:

$ Model = new Model ();
$ SQL = 'SELECT. id,. title, B. content from think_test1 as a, think_test2 as B where. id = B. ID '. $ map. 'order by. ID '. $ sort. 'limit '. $ p-> firstRow. ','. $ p-> listRows;
$ VoList = $ Model-> query ($ SQL );


4. multi-table query

The code is as follows:

$ Model-> field ('user. name, role. title ')-> table ('think _ user, think_role role')-> limit (10)-> select ();


Or:

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 help you design PHP programs based on the ThinkPHP framework.

Examples in this article describes how to use the associated query in ThinkPHP. Share it with you for your reference. The specific analysis is as follows: association in THINKPHP...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.