1. 程式人生 > >ThinkPHP join() table()方法的使用,多表查詢

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

itl prefix top file span mod sel highlight ble

table

[php] view plain copy
  1. $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

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