网站地图    收藏   

主页 > 后端 > thinkphp教程 >

THINKPHP 中关联查询 - Thinkphp

来源:自学PHP网    时间:2014-11-28 23:17 作者: 阅读:

[导读] THINKPHP 中关联查询(多表查询)可以使用 table() 方法或和join方法,请看示例:1、table()$list=$user-table( 39;user_statusstats,user...

THINKPHP 中关联查询

THINKPHP 中关联查询(多表查询)可以使用 table() 方法或和join方法,请看示例:

1、table()

  1. $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()

  1. $user = new Model('user'); 
  2. $list = $user->join('RIGHT JOIN user_profile ON user_stats.id = user_profile.typeid' )->select(); 

3、原生查询

  1. $Model = new Model(); 
  2. $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; 
  3. $voList = $Model->query($sql); 

多表查询

  1. $Model->field('user.name,role.title')->table('think_user user,think_role role')->limit(10)->select(); 

  1. $Model->field('user.name,role.title')->table(array('think_user'=>'user','think_role'=>'role'))->limit(10)->select(); 

自学PHP网专注网站建设学习,PHP程序学习,平面设计学习,以及操作系统学习

京ICP备14009008号-1@版权所有www.zixuephp.com

网站声明:本站所有视频,教程都由网友上传,站长收集和分享给大家学习使用,如由牵扯版权问题请联系站长邮箱904561283@qq.com

添加评论