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

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

admin10年前 (2015-07-26)技术文档1799
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/86.html

分享给朋友:

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

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

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

php简单分页类

<?php class page{            public $page; //当前页     publi...

wamp下虚拟主机的配置

1  编辑httpd.conf,查找Include conf/extra/httpd-vhosts.conf,把前面注释符号“#”删掉。 2  编辑httpd-vhosts.conf,我把WAMPServer安装在D:/wamp,所以我这里的路径是D:\wamp\Apache2\...

PHP利用Curl模拟登录并获取数据例子

PHP利用Curl模拟登录并获取数据例子

几乎所有的程序员来模仿用户登录或抓取数据都会使用到curl函数,下面我来给各位介绍利用curl函数实现登录并抓取数据,希望下面例子对各位有帮助。PHP的curl()在抓取网页的效率方面是比较高的,而且支持多线程,而file_get_contents()效率就要稍低些,当然,使用curl时需要开启下c...

wamp虚拟主机配置

1、首先打开apache的配置文件httpd.conf,并去掉#Include conf/extra/httpd-vhosts.conf前面的#,启用虚拟主机功能2、先把localhost配置好,免得以后访问localhost出现问题,我的wamp项目根目录是D:\wamp\www。将下面信息添加到...

如何在不同编程语言中获取现在的Unix时间戳(Unix timestamp)

如何在不同编程语言中获取现在的Unix时间戳(Unix timestamp)?先上代码进行java时间转换成unix timestampimport java.text.DateFormat;   import java.text.ParseExceptio...

发表评论

访客

看不清,换一张

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