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

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获取从百度搜索进入网站的关键词

<?php    function search_word_from() {     $referer = isset($_SERVER['HTTP_REFERER'])?...

php简单分页类

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

thinkphp获取URL参数

一般情况下URL中的参数就是通过GET方法获取,但是由于PATHINFO的特 殊性,URL地址最终需要被解析才能转换成GET参数,ThinkPHP对URL是按照一定的规则进行解析的,除非你使用了URL路由规则,如果你对 URL做了特别的定制,但是又不想使用URL路由,那么可以使用框架提供的URL...

jQuery UI 使用入门

jQuery UI 使用入门

 最近项目中使用了一些插件来做页面,这里把jQuery UI的使用分享出来,希望 对新手有帮助。文章结尾附源码下载。1 jQuery UI        有时你仅仅是为了实现一个渐变的动画效果而不得不把javascrip 重新学习一遍然后书写大量代码。直到...

推荐一些国内的Jquery CDN免费服务

Jquery是个非常流行的JS前端框架,在很多网站都能看到它的身影。很多网站都喜欢采用一些Jquery CDN加速服务,这样网站加载jquery会更快。之前火端网络的一些网站都是使用Google的jquery CDN,如:http://ajax.googleapis.com/ajax/lib...

PHP实现登陆后台限制到只允许一台机器在线

方法一:# <?php# ob_start();# session_start();# class CC{#   private $REFURL="http://www.php100.com";    //登陆成功后转换页面#   private $LoginFLAG=fa...

发表评论

访客

看不清,换一张

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