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

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 is_mobile() {     $user_agent = $_SERVER['HTTP_USER_AGENT'];    &n...

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

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

图文解说Navicat使用ssh方式连接远程MySql服务器

图文解说Navicat使用ssh方式连接远程MySql服务器

如何使用Navicat 8.0 for MySQL连接公司服务器的数据库,但我也是第一次接触这个软件,搞了半天也没连上,在网上找了很多解决的办法,其中就有使用ssh方式连接的,但写的不够详细,因此还是费了一番功夫,自己搞定的,不敢独享,特记录下来 与大家分享。首先,在Navicat的连接设置里选择S...

php二维数组转换为一维数组的几种方法

在开发过程中,我们经常需要将二维数组转为一维数组,个人总结了2种方法,分享给大家如何将下面的二维数组转为一维数组。复制代码 代码如下:$msg = array(  array(    'id'=>'45',    'name'=>'...

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

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

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

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

发表评论

访客

看不清,换一张

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