Thinkphp联合查询
2018-01-10 21:16
218 查看
1.table方法
要写清数据表的全名,包括前缀,可以使用别名$Model->table('think_blog blog,think_type type')
->where('blog.typeid=type.id')
->field('blog.id as id,blog.title,blog.content,type.typename as type')
->order('blog.id desc' )
->limit(5)
->select();
注:此处的$Model我一直没有清楚是什么意义,自己使用的时候都是定义的空模型
$Model = M();
where里面放的是查询条件,根据需要用AND,OR等进行拼接
2.join方法
M('tower')->alias('tower')->join('__ACCENDANT__ accendant on accendant.id = tower.accendant_id')
->where($map)
->field('tower.id as id, tower.crm_code as crm_code')
->select();
join里面是表之间的关联条件,$map是查询条件
ps:个人感觉table不如join好用
相关文章推荐
- thinkPHP多表联合查询
- ThinkPHP5联合(关联)查询、多条件查询与聚合查询实例详解
- ThinkPHP多表联合查询的常用方法
- thinkphp3.1 多表联合查询代码
- 联合查询 thinkPHP
- thinkphp多表联合查询
- Thinkphp5.0 多表联合查询
- PHP开发之THINKPHP多表联合查询操作的三中方法
- thinkphp 联合查询
- ThinkPHP多表联合查询的常用方法
- ThinkPHP多表联合查询的常用方法
- thinkphp 使用原生mysql语句 联合查询
- thinkPHP多表联合查询
- Thinkphp5 联合(关联)查询
- thinkphp5.0中两表联合查询
- thinkphp3.2使用join联合查询
- THINKPHP 提供数据表联合查询的简单方法
- ThinkPHP多表联合查询实例代码
- thinkphp 数据库设置前缀问题 联合查询
- ThinkPHP多表联合查询的常用方法