thinkPHP怎么实现多表查询

PHPz
Release: 2020-06-05 10:54:52
Original
2074 people have browsed it

thinkPHP怎么实现多表查询

thinkPHP怎么实现多表查询?

本文实例讲述了thinkPHP框架实现多表查询的方法。分享给大家供大家参考,具体如下:

我们可以将两个表连起来一起查询数据,我现在有两张表,一个是feedback表和member表,如图:

cf5da19b2613c4e139c56793f12114a.png

总目录:

a8b7ef99d708f704b67d88f80de26d4.png

上代码:

$where = array();
$where['meiyepin_feedback.member_id'] = "1";
$Model = M('feedback');
  $a = $Model
  ->join('meiyepin_member ON meiyepin_feedback.member_id = meiyepin_member.member_id')
  ->where($where)
  ->select();
var_dump($a);exit;
Copy after login

where的使用:

如果你要查询的字段只在一个表中有的话,那和平时的where的使用一样,但是如果你的查询字段同时存在在两张表格的话,那你就要加上表名,如上代码。

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!