try to change coding of your php file to "UTF-8 without BOM"
Whitespace Above HTML table created with PHP
-
22-09-2022 - |
Вопрос
I have mysterious whitespace above a table I created with both HTML (the header) and PHP (the body). When the PHP is used for the body, random whitespace that I don't want appears above the table. When I substitute the PHP for HTML, the white space goes away> Unfortunately, because I am display fluid information from a data base, I can't hardcode each row into the table using HTML.
Where is this random whitespace coming from and how can I get rid of it?
I have heard about extra whitespace in tag, or text not in tags causing a problem, but when I look at the page source, all the information echo's properly with not extra whitespace in tags or random text.
The echo'ed code/page source (the blank cells are intentional):
<tr><td>Name</td><td>2</td><td class="hasClass">Class</td><td class="hasClass">Class</td><td></td><td></td><td>0</td><td>15</td><td>No</td></tr>`
The HTML source code:
<table>
<tr><th>Name</th><th>No. of Parts</th><th>1<sup>st</sup> Block</th><th>2<sup>nd</sup> Block</th><th>3<sup>rd</sup> Block</th><th>4<sup>th</sup>Block</th><th>No. Enrolled</th><th>Limit</th><th>Requried</th></tr>
<tbody><?php include 'bin/table.php';?></tbody>
</table>
The PHP (table.php) assume a successful connection to the database:
while ($row = $result->fetch_row()) {
echo '<tr><td>'.$row[1].'</td><td>'.$row[2].'</td>';
if ($row[3] == 1) {
echo '<td class="hasClass">Class</td>';
} else {
echo '<td></td>';
}
if ($row[4] == 1) {
echo '<td class="hasClass">Class</td>';
} else {
echo '<td></td>';
}
if($row[5] == 1) {
echo '<td class="hasClass">Class</td>';
}
else {
echo '<td></td>';
}
if ($row[6] == 1) {
echo '<td class="hasClass">Class</td>';
} else {
echo '<td></td>';
}
if ($row[7] >= $row[8]) {
echo '<td style="color:white; background-color:red;">FULL</td>';
} else {
echo '<td>'.$row[7].'</td>';
}
if ($row[7] >= $row[8]) {
echo '<td style="color:white; background-color:red;">'.$row[8].'</td>';
} else {
echo '<td>'.$row[8].'</td>';
}
if ($row[9] == 1) {
echo '<td>Yes</td>';
} else {
echo '<td>No</td>';
}
echo '</tr>';
}
Thank you!
Решение