我有来自mysql数据库的3列结果。这些列具有正确的信息,但是列数据全部被压缩在一起,正如您在http://althedge.xyz/index2.html所看到的那样我对html知之甚少,并且我试图让列在页面上均匀分布。谁能告诉我如何实现这一目标?感谢
以下是代码:
<?php
// Database Settings
define('DB_HOST', 'localhost');
define('DB_PORT', '3306');
define('DB_USER', '*****');
define('DB_PASS', '*****');
define('DB_NAME', '*****');
// Connection to Database
$database = new MySQLi(DB_HOST, DB_USER, DB_PASS, DB_NAME, DB_PORT);
$sql = 'SELECT * '
. ' FROM posts';
$resultSet = $database->query($sql);
// Begin building some HTML output
$html = '<table border="0">
<tr>
<th>Column1</th>
<th>Column2</th>
<th>Column3</th>
</tr>';
while ($row = $resultSet->fetch_assoc())
{
$html .= '<tr>';
$html .= '<td>' . $row['Column1'] . '</td>';
$html .= '<td>' . $row['Column2'] . '</td>';
$html .= '<td>' . $row['Column3'] . '</td>';
$html .= '</tr>';
}
$html .= '</table>';
echo $html;
?>
答案 0 :(得分:0)
使用
<table border="0" style="width: 100%;">
使表格跨越页面的整个宽度。请注意,列仍将具有不同的大小。
要使所有列的间距相等,您可以使用
<table border="0" style="width: 100%; table-layout: fixed;">