【发布时间】:2018-07-05 04:57:21
【问题描述】:
我想在表格上显示一个文本文件并为每条记录分配一些代码。
- 我可以显示文本文件
- 我可以为每条记录分配代码(尚未完成,仍在开发中。)
但是,我遇到了一个问题。由于某种原因,表格列不匹配。
This is what happened. Heading 3 (Pink colour) the fields do not match the table.
下面是我的代码:
<table border='1'>
<tr>
<th>Heading 1</th>
<th>Heading 2</th>
<th>Heading 3</th>
</tr>
<?php
$file=file('number.txt');
foreach($file as $value){
$items = explode(" ", $value);
echo "<tr>";
echo "<td>$items[0]</td>";
echo "<td>$items[1]</td>";
}
include("connect.php");//connect to the database.
$sql = mysql_query("select * from code5 where Status='Active' LIMIT 8");
if (mysql_num_rows($sql) > 0)
{
while ($row = mysql_fetch_array($sql))
{
echo "<td>$row[Code]</td>";
echo "</tr>";
}
}
?>
</table>
有人能发现我错过了什么吗?或者帮我移动表格列?
我必须实现一个 CSS 文件来手动调整它吗?
【问题讨论】:
-
我不太清楚您要做什么。是否有什么东西可以将文件中的行与数据库中的行联系起来?
-
将最后一个
echo "</tr>";移到while循环外 -
如上图所示,粉红色的列没有到达顶部。 (你可以看到空白)有没有办法强制这个粉红色的柱子回到顶部?
-
@EXphpworld:您需要先将
echo "<tr>";也移动到外部foreach 循环中
标签: php html css html-table