目前,我正在用我的一个SQL表中的数据创建一个HTML表。但是,我想为每一列添加标题(注意:我不想使用数据库标题)。我该怎么做呢?下面是我当前没有标题的代码:
<?php
$searchResults = mysql_query("SELECT customerRefId, suburb, postcode, state FROM customer_seeking");
$num_rows = mysql_num_rows($searchResults);
?>
<table border="1">
<?php
while($row=mysql_fetch_array($searchResults))
{
echo"<tr><td>$row[customerRefId]</td><td>$row[suburb]</td><td>$row[postcode]</td><td>$row[state]</td></tr>";
}
?>
</table>发布于 2013-06-08 19:33:05
嘿,你可以使用下面的代码来标头:
<table border="1">
<tr><th>customer Ref Id</th><th>suburb</th><th>postcode</th><th>state</th></tr>
<?php
while($row=mysql_fetch_array($searchResults))
{
echo"<tr><td>$row[customerRefId]</td><td>$row[suburb]</td><td>$row[postcode]</td><td>$row[state]</td></tr>";
}
?>
</table>发布于 2013-06-08 19:30:37
刚添加到表下
<table border="1">
<th>Test</th>
<th>Test2</th>发布于 2013-06-08 19:31:18
在while循环之前输出标题行。
https://stackoverflow.com/questions/16999030
复制相似问题