I have some 'html' contents to display in php while loop. However, I want to have only 3 content blocks in every row and rendered html should be something like below:
<div class="row">
<div>Content Block</div>
<div>Content Block</div>
<div>Content Block</div>
</div>
<div class="row">
<div>Content Block</div>
<div>Content Block</div>
<div>Content Block</div>
</div>
<div class="row">
<div>Content Block</div>
<div>Content Block</div>
<div>Content Block</div>
</div>
This is how I tried it:
$output=[];
$i=0;
$html='';
while($row = $stmt->fetch()) {
if($i % 3 == 0) {
$html .= "<div class='row'>\n";
}
$html.="<div class='col-sm-4'>
<div class='room-box'>
<img src='$thumb' class='img-responsive' >
<h4>$name</h4>
</div>
</div>\n";
if($i++ % 3 == 2) {
$html .= "</div>\n";
$output[] = $html;
}
}
But its not working for me. Can anybody tell me What am I doing wrong? Thank you