php - Dynamic table cell contents appear outside of the <input> element that is placed inside <td>
I am buidling a table dynamically in a php page using code as shown below.
... ... ...
... ... ...
$a = array(5, 9, 10, 11, 12, 13, 14, 15, 16, 17);
foreach($data as $row){
echo "\t<tr>";
$number = 0;
foreach ($row as $value){
if (in_array ($number, $a)){
echo "<td><input/>" . $value . "</td>";
}
else{
echo "<td>" . $value . "</td>";
}
$number++;
}
echo "</tr>";
}
... ... ...
... ... ...
The php code is executed each time the page is loaded or on browser refresh with an AJAX call. When the page is loaded, the table appears as in the screenshot below.
As you see, the table cell contents appear outside of the element, and not inside it. How do I fix this? Any suggestions are most welcome!
Regards
Answer
Solution:
Try This
$a = array(5, 9, 10, 11, 12, 13, 14, 15, 16, 17);
foreach($data as $row){
echo "\t<tr>";
$number = 0;
foreach ($row as $value){
if (in_array ($number, $a)){
echo '<td><input type="text"id="powerString"name="powerString"value="'. $value .'"></td>';
}
else{
echo "<td>" . $value . "</td>";
}
$number++;
}
echo "</tr>";
}
Source