我有这段代码,目前显示的信息如下:
<?php
mysql_connect("localhost","example","password") or die("Could not connect to localhost");
mysql_select_db("exampledb") or die( "Could not connect to database");
$result = mysql_query("SELECT * FROM tablexample");
echo "<b>" . "Name" . "</b>" . " " . "<b>" . "Number" . "</b>";
echo "<br/>";
echo "<br/>";
while ($row = mysql_fetch_array($result))
{
echo ucwords($row['name']) . " " . ucwords($row['number']) . "<br>";
echo "<hr width='20%'>";
}
?>
Name Number
B (888) 888-3545
C (098) 545-4354
Cl (888) 888-3545
Da (888) 888-3545
H (888) 888-3545
H (888) 888-3545
Khzdf (888) 888-3545
但我希望它们像这样对齐(它应该覆盖每个名称有多少个字母并具有相同的空格:
Name Number
B (888) 888-3545
C (098) 545-4354
Cl (888) 888-3545
Da (888) 888-3545
H (888) 888-3545
H (888) 888-3545
Khzdf (888) 888-3545
-- 这是用 CSS 还是 PHP 完成的?
最佳答案
您是否考虑过使用表格?表格很棒....用于显示结构化数据
<table>
<thead>
<tr>
<th>Column1</th>
<th>column</th>
</tr>
</thead>
<tbody>
<tr>
<td>Column1 data</td><td>column 2 data</td>
</tr>
</tbody>
</table>
关于html - 在 PHP/HTML 中对齐信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15724926/