thinkphp两表,多表联合查询及分页的连贯操作写法
2024-08-24 01:08:29
- 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();
$data=$manage->table('template, app')->where('template.appid = app.appid')->field('template.teptype, app.appname')->order('template.id asc')->limit($Page->firstRow.','.$Page->listRows)->select();
最新文章
- Vijos1404遭遇战[最短路建模]
- CnBlog客户端Windows Live Write安装方法
- expdp和impdp的用法
- cf A. Inna and Pink Pony(思维题)
- 采用jsp用表格的形式显示
- (六)backbone - API学习 - Backbone路由
- 【转载】安装和使用花生壳(linux)
- YARN的capacity调度器主要配置分析
- dev gridcontrol 绑定int型及日期型的列默认当值为0时显示空白及格式化日期显示方式
- find指令参数
- [译][待续]Chap1.Using neural nets to recognize handwritten digits
- android 动态string
- getcomputedstyle()获取border像素差异问题
- windows 命令直接搜索局域网计算机的ip
- SpringCloud使用Prometheus监控(基于Eureka)
- FTP:500 OOPS: failed to open vsftpd log file:/var/log/vsftpd.log
- yolov3实践(二)
- SpringBoot处理静态资源的两种方式
- Js基础知识1-数组操作全解
- web前端设计规范