Answer the question
In order to leave comments, you need to log in
How to make a closing tag after displaying four elements?
Good afternoon.
There was a small problem. For the test I deduce records from a DB.
<? foreach ($data as $row): ?>
<div class="col-xs-12 col-sm-6 col-md-3 col-lg-3">
<div class="game-element">
<img src="<?=$row['POSTER']?>"><br>
<a href="?id=<?=$row['ID']?>" class="game-title"><?=$row['TITLE']?></a>
</div>
</div><!--game-element -->
<? endforeach ?>
Answer the question
In order to leave comments, you need to log in
Find out when the 4th element is:
$counter = 0;
foreach ($data as $row) {
$counter++;
if ($counter % 4 === 0)
{
//4-й элемент
}
}
stackoverflow.com/questions/13270870/wrapping-a-di...
I think you can write a four yourself instead of a three)
<div class="container">
<?php $i = 0; ?>
<?php foreach ($data as $row): ?>
<div class="col-xs-12 col-sm-6 col-md-3 col-lg-3">
<div class="game-element">
<img src="<?=$row['POSTER']?>"><br>
<a href="?id=<?=$row['ID']?>" class="game-title"><?=$row['TITLE']?></a>
</div>
</div><!--game-element -->
<?php
$i++
if ($i == 4) {
$i = 0;
echo '</div><div class="container">';
}
?>
<?php endforeach ?>
<div>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question