maybe I am just too tired or missing something really fundamental, but I am growing frustrated.
I have table which contains data. I wrote php function which takes data from database and construct html table.
My problem is, that first row in table misses element in last table cell.
PHP function:
function printTable($stmt) {
$result = '<table>';
while ($data = $stmt -> fetch()) {
$result .= '<tr>'
. '<td><span>' . $data['id'] . '</span></td>'
. '<td><span>' . $data['name'] . '</span></td>'
. '<td>'
. '<form method="post" action="">'
. '<input type="hidden" name="id" value="' . $data['id'] . '">
. '<button type="submit" name="edit">Edit</button>'
. '</form>'
. '</td>'
. '</tr>';
}
$result .= '</table>';
return $result;
}
The problem is that browser ignores form element in first row. Hidden input and button stay in place but without its parent form. So the output in browser looks like this:
<table>
<tr>
<td><span>1</span></td>
<td><span>Foo</span></td>
<td>
<input type="hidden" name="id" value="1">
<button type="submit" name="edit">Edit</button>
</td>
</tr>
<tr>
<td><span>2</span></td>
<td><span>Bar</span></td>
<td>
<form method="post" action="">
<input type="hidden" name="id" value="2">
<button type="submit" name="edit">Edit</button>
</form>
</td>
</tr>
<tr>
<td><span>3</span></td>
<td><span>Foo Bar</span></td>
<td>
<form method="post" action="">
<input type="hidden" name="id" value="3">
<button type="submit" name="edit">Edit</button>
</form>
</td>
</tr>
</table>
Furthermore, if I dump return value of this function, for example: var_dump(htmlspecialchars(printTable($stmt)));
it shows that first form is there, but in browser suddenly misses. Is it mysteriously dissapearing form magic?