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:
------Solution--------------------
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 (' 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 ()
$user = new Model (' user ');
$list = $user->join (' Right join user_profile on user_stats.id = User_profile.typeid ');
3. Native Query
$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);