Thinkphp Associated queries related issues

Source: Internet
Author: User
Thinkphp Associated Query problems
There are two tables, one is the hospital r_hospital, the other is the department r_department. How to correlate the query, after the selection of the hospital, the department only shows the department of the hospital, and does not show the other hospital thinkphp Correlation Query

Share to:

thinkphp Query (multi-table query) can use the table () method or the Join method, see the example:

1. Table ()

$list = $user->table (' User_status stats, user_profile profile ')->where (' = Profile.typeid ')->field (' as ID, stats.display as display, profile.title as title,profile.content as content ')->order (' desc ')- >select ();

2. Join ()

$user = new Model (' user ');

$list = $user->join (' Right join user_profile on = User_profile.typeid ');

3. Native Query

$Model = new Model ();

$sql = ' Select,a.title,b.content from think_test1 as a, think_test2 as B where '. $map. ' ORDER by '. $sort. ' Limit ' $p->firstrow. ', '. $p->listrows;
$voList = $Model->query ($sql);
  • Related Article

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