我正在研究一些从数据库创建表的 PHP,这一部分让我很困惑,表标题和页脚的呼应非常好,但是行被拆分了,里面的内容被放在了表之外,但是得到正确放入:
这是它的样子:
$STH = $DBH->query($query_complete);
// Perform the query
$STH->setFetchMode(PDO::FETCH_ASSOC);
$row = $STH->fetch();
// Initialize our variables used for row counts, etc.
$i = 0;
$prevRowHour = 25; // Start at 25th hour as nothing will match this first-up.
$rowCount = $STH->rowCount();
if($rowCount==0) {
echo 'There are no results for this time frame.';
}
else {
// Create our table heading
echo <<<EOD
<table class="tablesorter" id="trendTable">
<thead>
<tr>
<th>Hour added</th>
<th>Case Number</th>
<th>Device</th>
<th>Component</th>
<th>Tier</th>
<th>Resolved</th>
<th>Exact Time Added</th>
</tr>
</thead>
<tbody>
EOD;
// Save the output into a variable to output after the sort order div
while($row = $STH->fetch()) {
// Check if this hour matches the last.
if ($prevRowHour != $row['hour'] ) {
// If it doesn't -> Create new row
// Then make our fresh row
/* ~~~THIS LINE OUTPUTS WEIRDLY~~~ */ echo '<tr colspan="7">'.$row['hour'].'</tr>'; // THIS OUTPUTS ALL WEIRDLY
}
// Either way, we add a new row.
$prevRowHour = $row['hour'];
$i++;
}
echo <<<EOD
</tbody>
</table><!-- end of trendTable -->
EOD;
}
似乎有问题的行是:
/* THIS LINE OUTPUTS WEIRDLY */ echo '<tr colspan="7">'.$row['hour'].'</tr>'; // THIS OUTPUTS ALL WEIRDLY
根据元素检查器,这是该段已输出的 HTML 部分(在 OS X 上的 Chrome、Safari 和 FireFox 中测试):
http://i.stack.imgur.com/tGUmF.png
然而在视图源中:它正确显示:
..<tbody><tr colspan="7">13</tr><tr colspan="7">11</tr><tr colspan="7">10</tr>..
我已删除所有 javascript 并禁用它以确认这不是外部问题。它发生在没有 css/nojs 并且是来自 PHP 的纯 HTML 时。
我还将所有回显的 EOD 切换为常规的单行字符串。
有没有人以前见过这样的事情,并且可能知道如何阻止它?