I’m creating a three column table of form fields with the code below. Each row has three columns. If the total number of fields is not a multiple of three then the last row doesn’t contain blank form fields in the remaining columns.
How can I amend this to complete the remaining columns with blank form fields?
<?php
$listCount = count($col);
for ($i = 0; $i < $listCount; ++$i) {
if($i % 3 == 0) {
echo '<tr class="list_row">';
} ?>
<td><input type="text" style="width: 190px;" name="inputCol1[]" value="<?php echo $col[$i] ?>" /></td>
<?php
if($i % 3 == 3) {
echo '</tr>';
}
}
?>
You need to complete the last row after the
forloop:Also, take a look at the comments below your question as
$i % 3will never be3.Note: I really should combine the
ifanddoin one nice condition / loop, but it’s too late for that, this should at least work…