Thinkphp Association query
There are two tables: Hospital r_hospital and department r_department. After you select a hospital, the department displays only the Department of the hospital, but not the department of other hospitals.
Reply to discussion (solution)
Post your code
Post your code
Class RoomAction extends Action {
Public function room (){
$ Room = M ('Department ');
$ H_id = I ('Get. h_id ');
$ H_name = I ('Get. h_name ');
Print_r ($ h_id );
Print_r ($ h_name );
$ Data = $ _ POST ['text'];
Print_r ($ data );
If ($ data! = ''){
// Execute the SQL statement (execute like query, search)
$ Map ['name'] = array ('like', "% $ data % ");
$ List = $ room-> where ($ map)-> select ();
$ This-> list = $ list;
$ This-> display ();
} Else {
$ Map ['hospital _ id'] = $ h_id;
$ List = $ room-> where ($ map)-> select ();
$ This-> assign ("list", $ list );
$ This-> display ();
}
}
Join queries (multi-table queries) in THINKPHP can use the table () method or join method. see 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. 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 );