Uffo
Uffo

Reputation: 10056

Add tr element on even number

So I have a <tr> which I want to open <tr> and close </tr> every 2nd time

So I have tried this:

<?php $i = 0; foreach($blogs as $story): ?>
<?=(($i % 2) == 0) ? "<tr>" : null ?>
 <td>my stuff</td>
<?=(($i % 2) == 0) ? "</tr>" : null ?>
<?php ++$i; endforeach; ?>

But it adds every time, my need is to have one <tr> with two <td> inside

<tr><td></td><td></td></tr>

Upvotes: 3

Views: 76

Answers (1)

nickn
nickn

Reputation: 184

Shouldn't it be <?=(($i % 2) == 1) ? "</tr>" : null ?> cause you have it <?=(($i % 2) == 0) ? "</tr>" : null ?>

Upvotes: 2

Related Questions