php - 如何将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"]. " " . $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>
解决方案
您可以使用 SQL JOIN 来匹配两个表中的值。
实施取决于您的表结构
推荐阅读
- node.js - 使用 ejs 和 node.js 更新 mongodb 集合中的属性
- hibernate - Hibernate 调用影响 Bean 类对象的存储过程/存储函数
- angular - Cognito 登录工作正常,但在浏览器中出现 400 错误
- javascript - 基于二维网格的碰撞
- python - 在多个 CSV 文件的末尾添加具有特定文件名的列和行
- ios - 使用 AVAssetExportSession 在最终视频中截断视频
- .net - 如何检查 Windows 上安装的 .Net 框架
- excel - 从 Excel 中的其他表创建可排序表
- selenium - Robotframework:如何使用 Tabindex 作为定位器?
- php - 检查数组键是否存在且为空字符串的最佳方法