我正在尝试从mysql查询中渲染4列但是我无法正确对齐输出值,如何格式化表格,所以所有4列和标题都要对齐中心?
$tableStyle = "padding: 5px;border:1px";
$tdStyle = "padding:5px ";
echo '<table style="' . $tableStyle . '" cellpadding="5" cellspacing="5">';
echo "<tr align='center'> <th>Title</th><th>Score</th><th>Maximum Score</th><th>Finished On</th></tr>";
$row = $database->loadRowList();
foreach($row as $valuearray)
{
echo '<tr style=" align="center">';
foreach($valuearray as $field)
{
echo "<td align='center'>$field</td>";
}
echo "</tr>";
}
echo "</table>";
答案 0 :(得分:0)
将数据包含在另一个包含一个单元格的表中并将其居中,以便HTML看起来像这样:
<table><tr align='center' valign='middle'><td><table>...</table></td></tr></table>
答案 1 :(得分:0)
$tableStyle = "padding: 5px;border:1px";
$tdStyle = "padding:5px ";
echo '<table style="' . $tableStyle . '" cellpadding="5" cellspacing="5">';
echo "<tr> <th align='center'>Title</th><th align='center'>Score</th><th align='center'>Maximum Score</th><th align='center'>Finished On</th></tr>";
$row = $database->loadRowList();
foreach($row as $valuearray)
{
echo '<tr>';
foreach($valuearray as $field)
{
echo "<td align='center'>$field</td>";
}
echo "</tr>";
}
echo "</table>";
对齐中心不应放在tr
上