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

admin10年前技术文档1905
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();


分享到:

相关文章

php批量下载图片

假如现在我现在发现一个网站上的图片保存方式是1001 – 1999目录下都存放着从1开始(数量不等)的.jpg图片,现在我决定用php的方法将图片按照自己需要的样式直接下载到本地...

centos 配置samba服务器

centos 配置samba服务器

yum install samba* -yvi /etc/samba/smb.conf复制[printers],重新创建一个web应用[homes]     ...


这里我选择centos7-x86 64 右键 复制链接。

在centos系统中执行

centos7 安装最新版postgresql10

    一、更新源地址:https://yum.postgresql.org/repopackages.php这里我选择centos7-x86 64 右键 复制...

php的rabbitmq队列持久化设置

php的rabbitmq队列持久化设置,这个功能是一个十分伟大的功能,我们在ecshop注册发短信的时候,或者程序要发邮件的时候,往往会拖跨网络速度,在高并发的时候,这个时候我们将数据写到队列中,通过...

公共DNS

阿里云: 223.6.6.6 223.5.5.5 百度: 180.76.76.76 联通: 123.125.81.6 218.30.118.6 114: 114.114....

php 在web端来播放amr语音(如微信语音)

说下整体思路1、服务器安装ffmpeg2、使用ffmpeg -i 指令来转换amr为mp3格式(这个到时候写在PHP代码中,使用system函数执行即可)3、在网页端使用HTML5的audio标签来播...

发表评论    

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