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

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 获取页面内容

function get_contents($url){     if(function_exists('file_get_contents')){       &nbs...

php检查用户名是否符合规定

<?php   /**  * 检查用户名是否符合规定 (两个字符以上,只能有中文,字母,数字,下划线的)  *  * @param STRING $username 要检查的用户名...

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

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

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

 PHP二维数组的矩阵转置

PHP二维数组的矩阵转置

<?php    $arr1 = array(               array(1,2,3),            &nbs...

浅谈 PHP 与手机 APP 开发(API 接口开发)

文章转载自:http://www.thinkphp.cn/topic/5023.html这个帖子写给不太了解PHP与API开发的人一、先简单回答两个问题:1、PHP 可以开发客户端?答:不可以,因为PHP是脚本语言,是负责完成 B/S架构 或 C/S架构 的S部分,即:服务端的开发。(别去纠结 GT...

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

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

发表评论

访客

看不清,换一张

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