您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

ThinkPHP多表联合查询的常用方法

2024/2/26 17:29:22发布16次查看
这篇文章主要介绍了thinkphp多表联合查询的常用方法,对于项目开发非常重要!需要的朋友可以参考下
thinkphp中关联查询(即多表联合查询)可以使用 table() 方法或和join方法,,具体使用如下例所示:
1、原生查询示例:
$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);
2、join()方法示例:
$user = new model('user');$list = $user->join('right join user_profile on user_stats.id = user_profile.typeid' );
3、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();
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product