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

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

admin11年前 (2015-09-25)技术文档1926
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...

php登录函数login session+mysql

<?php // 为php和mysql剔除不安全html代码。 //http://blog.ddian.cn function safestrip($string){    $string = strip_tags(...

php获取从百度搜索进入网站的关键词

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

抓取最近八天天气(非利用接口,直接从网站提取)

<?php    /*     *特别注意,第一天没有最高气温数据,第八天没有最低气温数据     *注意对数字进行过滤时不要忘记对负号进行判断   &nb...

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

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

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

wamp下虚拟主机的配置

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

发表评论

访客

看不清,换一张

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