thinkphp3.1多表关联查询
2015-08-04 18:36
671 查看
THINKPHP 中关联查询(多表查询)可以使用 table() 方法或和join方法,请看示例:
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、原生查询
$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);
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、原生查询
$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);
相关文章推荐
- php mygetype typeof 变量的数据类型
- php -l filename.php 来检查语法
- 浏览器上传文件到PHP的几种方法
- php--字符转义
- php--字符转义
- php--字符转义
- js与php传递参数
- iis8 php 去除index.php配置web.config报500错误
- php header函数详解
- php 计算两个文件之间的相对路径方法
- YII 获取系统级请求参数的常用方法
- PHP写文件到指定位置
- php汉字繁简体互转扩展:openccpp
- S3C2440 U盘,以及自动挂载顺序(inittab,fstab,mdev,hotplug)
- php性能优化
- 出现Warning: Cannot modify header information - headers already sent by ..的解决办法
- thinkphp 模板读取
- JRTPLIB编译说出现的问题及解决方法(转载)
- PHP学习(变量)
- php ocket通信机制