首页 > 解决方案 > 如何将2个mysql数据表中的数据列出到html表中

问题描述

在我的 mysql 数据库中有 2 个名为 tblapps 和 tblapps2 的表。我已将应用程序的一些数据存储在 tblapps 中,其余数据存储在 tblapps2 中。在我的应用程序的后端,目前正在显示 tblapps 的所有数据,但突然我有一个要求,我希望在 tblapps2 中再显示一列,列名为“country”,mysqli 表列名为“precountry”。这对我来说是全新的,无论如何我都不会这样做。

如果有任何帮助,我们将不胜感激。

<div class="portlet-body flip-scroll">                                                      
                                <?php                                                           
                                $sql = "SELECT * FROM tblapps order by id desc";                            
                                $result = $connect->query($sql);                            
                                if ($result->num_rows > 0) {
                                    echo "<table class='display' id='example'>
                                          <thead class='flip-content'>

                                            <tr>
                                                <th>ID</th>
                                                <th>App ID</th>
                                                <th>Full Name</th>
                                                <th>Journey Date</th>
                                                <th>App type</th>
                                                <th>Visa Type</th>
                                                <th>Fee</th>
                                                <th>Nationality</th>
                                                <th>Country</th>
                                                <th>Submit Date</th>
                                                <th>payment</th>
                                                <th>status</th>
                                            </tr>

                                            </thead>";                                                                                                               
                                      while($row = $result->fetch_assoc()) {
                                             echo"<tr>
                                                <td>" . $row["id"]. "</td>
                                                <td><a href=\"formdetails.php?app_id=".$row["app_id"]."\">". $row["app_id"]. "</a></td>
                                                <td>" . $row["firstname"]. "&nbsp;" . $row["lastname"]."</td>
                                                <td>" . $row["journeydate"]. "</td>
                                                <td>" . $row["appl_type"]. "</td>
                                                <td>" . $row["visatype"]. "</td>
                                                <td>" . $row["visa_fee"]. "</td>
                                                <td>" . $row["nationality"]. "</td>
                                                <td>" . $row["precountry"]. "</td>
                                                <td>" . $row["sdate"]. "</td>
                                                <td>" . $row["pay_status"]. "</td>
                                                <td>" . $row["appstatus"]. "</td>
                                                </tr>"; }
                                    echo "</table>";                                } else {    echo "0 results";}$connect->close();?>
                                </div>

标签: phpmysqli

解决方案


您可以使用 SQL JOIN 来匹配两个表中的值。

实施取决于您的表结构


推荐阅读