生成 HTML 以并排放置来自 PHP 的两个表
Generating HTML to place two tables side by side from PHP
我想在 HTML table 中并排显示两个 table(均按不同的列排序)。尝试:
<tbody>
<td>
<?php
require_once "db_data.php";
$bids_results = $mysqli->query("SELECT bid_volume, bid FROM apple_bids ORDER BY bid DESC");
while($bids = $bids_results->fetch_array()) {
echo "<tr>\n\t<td>"
. $bids['bid_volume']
. "</td>\n\t<td>"
. $bids['bid']
. "</td>\n</tr>\n";
}
$bids_results->close();
?>
</td>
<td>
<?php
$offers_results = $mysqli->query("SELECT offer_volume, offer FROM apple_offers ORDER BY offer DESC");
while($offers = $offers_results->fetch_array()) {
echo "<tr>\n\t<td>"
. $offers['offer']
. "</td>\n\t<td>"
. $offers['offer_volume']
. "</td>\n</tr>\n" ;
}
$offers_results->close();
$mysqli->close();
?>
</td>
</tbody>
但出于某种原因,第二个 table 显示在第一个下方。如果我将两个 <td>
放在 <tbody>
下面的一个 <tr>
中,也会发生同样的情况
试试这个标记:
<table>
<tr>
<td>
<!-- PHP output here -->
</td>
<td>
<!-- PHP output here -->
</td>
</tr>
</table>
您真的不需要使用 tbody
,因为它会由浏览器生成。使用您的代码,正确的 table 结构将类似于以下内容:
<table>
<tr>
<td>
<table>
<?php require_once "db_data.php"; $bids_results=$ mysqli->query("SELECT bid_volume, bid FROM apple_bids ORDER BY bid DESC"); while($bids = $bids_results->fetch_array()) { echo "
<tr>
<td>" . $bids['bid_volume'] . "</td>
<td>" . $bids['bid'] . "</td>
</tr>"; } $bids_results->close();
?>
</table>
</td>
<td>
<table>
<?php $offers_results=$ mysqli->query("SELECT offer_volume, offer FROM apple_offers ORDER BY offer DESC"); while($offers = $offers_results->fetch_array()) { echo "
<tr>
<td>" . $offers['offer'] . "</td>
<td>" . $offers['offer_volume'] . "</td>
</tr>" ; } $offers_results->close(); $mysqli->close();
?>
</table>
</td>
</tr>
</table>
我想在 HTML table 中并排显示两个 table(均按不同的列排序)。尝试:
<tbody>
<td>
<?php
require_once "db_data.php";
$bids_results = $mysqli->query("SELECT bid_volume, bid FROM apple_bids ORDER BY bid DESC");
while($bids = $bids_results->fetch_array()) {
echo "<tr>\n\t<td>"
. $bids['bid_volume']
. "</td>\n\t<td>"
. $bids['bid']
. "</td>\n</tr>\n";
}
$bids_results->close();
?>
</td>
<td>
<?php
$offers_results = $mysqli->query("SELECT offer_volume, offer FROM apple_offers ORDER BY offer DESC");
while($offers = $offers_results->fetch_array()) {
echo "<tr>\n\t<td>"
. $offers['offer']
. "</td>\n\t<td>"
. $offers['offer_volume']
. "</td>\n</tr>\n" ;
}
$offers_results->close();
$mysqli->close();
?>
</td>
</tbody>
但出于某种原因,第二个 table 显示在第一个下方。如果我将两个 <td>
放在 <tbody>
<tr>
中,也会发生同样的情况
试试这个标记:
<table>
<tr>
<td>
<!-- PHP output here -->
</td>
<td>
<!-- PHP output here -->
</td>
</tr>
</table>
您真的不需要使用 tbody
,因为它会由浏览器生成。使用您的代码,正确的 table 结构将类似于以下内容:
<table>
<tr>
<td>
<table>
<?php require_once "db_data.php"; $bids_results=$ mysqli->query("SELECT bid_volume, bid FROM apple_bids ORDER BY bid DESC"); while($bids = $bids_results->fetch_array()) { echo "
<tr>
<td>" . $bids['bid_volume'] . "</td>
<td>" . $bids['bid'] . "</td>
</tr>"; } $bids_results->close();
?>
</table>
</td>
<td>
<table>
<?php $offers_results=$ mysqli->query("SELECT offer_volume, offer FROM apple_offers ORDER BY offer DESC"); while($offers = $offers_results->fetch_array()) { echo "
<tr>
<td>" . $offers['offer'] . "</td>
<td>" . $offers['offer_volume'] . "</td>
</tr>" ; } $offers_results->close(); $mysqli->close();
?>
</table>
</td>
</tr>
</table>