当前位置:首页 > 技术文档 > 正文内容

PHP开发之THINKPHP多表联合查询操作的三中方法

admin10年前 (2015-09-25)技术文档1925
THINKPHP 中关联查询(多表查询)可以使用 table() 方法或和join方法,请看示例: 

联合查询
        1、原生查询
        $sql =$sql='select p.product_name,z.message as zmessage,z.rdtime,r.message,r.rdtime from wsd_product as p,wsd_product_zixun as z,wsd_product_zixun_reply as r where p.id=z.lipin_id and z.id=r.zixun_id order by z.rdtime';
        $list = $Form->query($sql);
        2、join() 两表查询
        $list = $Form->join('think_sort ON think_form.sort_id = think_sort.sort_id' )->select();
        3、join() 多表查询
        $list = $Form->join('think_sort ON think_form.sort_id = think_sort.sort_id' )->join('think_brand ON think_form.brand_id = think_brand.brand_id' )->select();
        4、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();


分享到:

扫描二维码推送至手机访问。

版权声明:本文由云河空间发布,如需转载请注明出处。

本文链接:http://yuyunhe.cn/index.php/post/105.html

分享给朋友:

“PHP开发之THINKPHP多表联合查询操作的三中方法” 的相关文章

php 使用curl模拟登录discuz以及模拟发帖

<?php $discuz_url = 'http://127.0.0.1/discuz/';//论坛地址 $login_url = $discuz_url .'logging.php?action=login...

利用ctrl+v实现粘贴截图完成上传功能

<?php header("Access-Control-Allow-Origin:*"); $url  = 'http://'.$_SERVER['HTTP_HOST']; $file =&nb...

dz中“QQ互联”出现Discuz! Database Error解决办法

dz中“QQ互联”出现Discuz! Database Error解决办法

dz中QQ登陆出现Discuz! Database Error解决办法dz站长朋友相信肯定有人遇到做的QQ互联登录,根本没法用,这让网站的社交登录性能大打折扣,这么解决?下面就看大神的神操作!...

PHP实现百度、网易、新浪短网址服务的API接口调用

[导读] 看了几个短网址API服务,于是把它们整理出来,方便以后使用,目前,提供靠谱的短网址API接口的公司不多(谷歌、百度、新浪微博、网易等),而像腾讯微博、淘宝这几个巨头的短网址服务都是...    PHP实现百度、网易、新浪短网址服务的API接口调用  ...

CentOS minimal版安装图形界面的步骤

1、连接网络:CentOS minimal.iso安装好后,进入终端,默认是不开网络的,首先启用网卡, 自动获取ip.ifconfig eth0 up   www.2cto.com dhclient eth0这时候再 ifconfig 一下,就可以看见已经自动分配好IP...

解决The current branch is not configured for pull No value for key branch.master.merge found in config

1.在本地工程目录找到config文件(我的是在D:\wamp\youthstartup\.git);2.修改config文件内容为:[core]    repositoryformatversion = 0    filemode = false ...

发表评论

访客

看不清,换一张

◎欢迎参与讨论,请在这里发表您的看法和观点。