Brian Ramsey February 2016

php/datatables generate table using foreach but need an additional <td></td> at end

I am using datatables and generating my table using a foreach, but I need one last to contain the options (edit, etc). I cannot think how to most efficiently do this, I can think to do it using a counter and then when the output has ended place an if statement (rows = rows then) to put these last td's in... I am hoping someone has a better way using my current syntax?

                        <?php foreach($results as $row):?>
                            <tr>
                                <?php foreach($row as $cell): ?>
                                    <td>
                                        <?php echo $cell ?>
                                    </td>
                                <?php endforeach; ?>
                            </tr>
                        <?php endforeach; ?>

Answers


Gouda Elalfy February 2016

you can put then after internal for like this:

<?php foreach($results as $row):?>
<tr>
<?php foreach($row as $cell): ?>
<td>
<?php echo $cell ?>
</td>
<?php endforeach; ?>
<td>edit </td> <td>show</td><td>delete</td>
</tr>
<?php endforeach; ?>

Post Status

Asked in February 2016
Viewed 2,425 times
Voted 9
Answered 1 times

Search




Leave an answer