我有一个名为航班详情的MySQL表,如下所示:
预期结果:
不在同一个城市。
答案 0 :(得分:1)
试试这个,
$conn = mysqli_connect("localhost", "username1", "password1", "databse1");
$conn1 = mysqli_connect("localhost", "username2", "password2", "database2");
$result = '';
$query = "SELECT * FROM database1.table1";
$sql = mysqli_query($conn, $query);
$result .='
<table class="table table-bordered">
<tr>
<th width="20%">ID</th>
<th width="10%">Qty</th>
</tr>';
if (mysqli_num_rows($sql) > 0)
{
while ($row = mysqli_fetch_array($sql))
{
$query1 = "SELECT * FROM database2.table1 where table1.id = " . $row['id'];
$sql1 = mysqli_query($conn1, $query1);
if (mysqli_num_rows($sql1) > 0)
{
while ($row1 = mysqli_fetch_array($sql1))
{
$result .='<tr>
<td>' . $row1["id"] . '</td>
<td>' . $row1["qty"] . '</td>
</tr>';
}
}
}
}
else
{
$result .='
<tr>
<td colspan="5">No Item Found</td>
</tr>';
}
$result .='</table>';
echo $result;