简体   繁体   English

使用Inner Join MySQL php从3表中获取数据

[英]Get data from 3 table with Inner Join MySQL php

include '../incs/connect.php';
    $q=mysqli_query($con,"SELECT appl_reg_details.appl_id, appl_reg_details.apl_name, appl_reg_details.apl_email, rp_test_result.appl_status, rp_intv_result.intv_obt_marks
                          FROM appl_reg_details
                          INNER JOIN rp_test_result ON appl_reg_details.appl_id = rp_test_result.appl_id
                          INNER JOIN rp_intv_result ON rp_test_result.appl_id = rp_intv_result.appl_id
                          GROUP BY appl_reg_details.appl_id
                          ");
    WHILE($row=mysqli_fetch_array($q))
    {
        echo $row=['appl_id']." - ";
        echo $row=['apl_name']." - ";
        echo $row=['intv_obt_marks']." - ";
        echo $row=['appl_status']." -";
        echo $row=['apl_email']."<br/>";
    }

I have 3 tables and i want to get data of 3 field from table1, of 1 field from table 2 and table 3 each, i have found that inner join can do this, when i run this it says 'Notice: Array to string conversion', help to correct this or give a new way please 我有3个表,我想从表1中获取3个字段的数据,从表2和表3中分别获取1个字段的数据,我发现内部联接可以做到这一点,当我运行它时,它说“注意:数组到字符串的转换',请帮助纠正此问题或提供新方法

The query looks fine at first glance. 乍一看,查询看起来很好。

The problem is with the lines below it. 问题在于它下面的线。 They include an unnecessary = : 它们包括不必要的=

echo $row=['apl_email']."<br/>";

These lines should be like this: 这些行应如下所示:

echo $row['apl_email']."<br/>";

Performance benefits aside, GROUP BY serves no purpose here other than to confuse the result set. 除了性能优势外,GROUP BY在这里除了混淆结果集之外没有其他用途。 Try something like this instead, and fix the coding errors identified by rjdown: 尝试这样的方法,并修复rjdown标识的编码错误:

SELECT DISTINCT d.appl_id
              , d.apl_name
              , d.apl_email
              , t.appl_status
              , i.intv_obt_marks
           FROM appl_reg_details d
           JOIN rp_test_result t
             ON t.appl_id = d.appl_id 
           JOIN rp_intv_result i 
             ON r.appl_id = i.appl_id;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM