ThinkPHP join() table()方法的使用,多表查询

ThinkPHP常用的两个多表查询方法,table() join()

table

[php] view plain copy
 
  1.       
  2. $list = M()->table('user1 a, user2 b')->where('a.id = b.id')->field('a.name,b.sex')->order('a.id desc')->select();  
join
[php] view plain copy
 
  1. $pre = C('DB_PREFIX');  
  2. M("user u")->join("{$per}user_info x ON x.uid = u.id")->where("u.id = $uid")->find();  
 
另外,两个表中若有同名字段都要查询的话,用这样的写法: filed('a.*,b.name as username,b.sex')

记录官网的一篇教程
http://www.thinkphp.cn/topic/9332.html
posted @ 2017-12-25 11:22  jamescr7  阅读(537)  评论(1编辑  收藏  举报