The Join method of thinkphp

Source: Internet
Author: User

Two tables:

Table One: Pre_company_member Association fields: comp_id

Table II: Pre_company Associated fields: comp_id

Query the data in both tables.

Method One: Hump method

$member =m (' Companymember ');

$member _info= $member->join (' Pre_company on pre_company_member.comp_id=pre_company.comp_id ')->where (Array (' Pre_company_member.uid ' =>array (' EQ ', session (' UID '))))->selsect ();

Method Two: Alias method

$member =m ();

$member _info= $member->table (' pre_company_member m ')->join (' Pre_company C on m.comp_id=c.comp_id ')->where ( Array (' M.uid ' =>array (' EQ ', session (' UID '))))->selsect ();

Attention:

The default is the inner join method, if you need to use a different join method, you can change to

    1. $Model->join(‘RIGHT JOIN __WORK__ ON __ARTIST__.id = __WORK__.artist_id‘)->select();

or use:

    1. $Model->join(‘__WORK__ ON __artist__.id = __WORK__.artist_id‘,‘RIGHT‘)->select();

The type of support for the second parameter of the Join method includes: INNER left-right-full.

the Join method can only be used once if the parameters of the join method are in an array, and cannot be mixed with the string method. For example:

    1. join(array(‘ __WORK__ ON __ARTIST__.id = __WORK__.artist_id‘,‘__CARD__ ON __ARTIST__.card_id = __CARD__.id‘))

in the case of array mode, the second argument is invalid. The join type must therefore be explicitly defined in the string , for example:

    1. join(array(‘ LEFT JOIN __WORK__ ON __ARTIST__.id = __WORK__.artist_id‘,‘RIGHT JOIN __CARD__ ON __ARTIST__.card_id = __CARD__.id‘))

Join method for 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.