您的位置:首页 > 编程语言 > PHP开发

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好用
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: