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...