Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to define html tag after each 5 iteration in foreach loop

I just want to know how to define HTML Tag <br clear="all"> after each 5 iteration in foreach loop here is my code

<?php
$i=1;    
foreach($videoEntries as $data){
?>
    <div class="item-main">
        <div class="item">
        <a href="javascript:;" onclick="ratePopup(2)" title="<?php echo $data->video_name;?>">
        <div class="overlaid"></div>
        <img src="<?php echo $image_url;?>"  width="93" height="89"/>
        </a>
        </div>
        <p title="Trailer Name"><strong><?php echo $data->video_name;?></strong></p>
        <p title="Released Date"><?php echo $data->video_released_date;?></p>
    </div>
<?php 
    if($i == 5){
        echo "<br clear = 'all'>";    
    }
}
?>

Result Required or helps are definitely appricicated

12345
<br clear="all">
678910
<br clear="all">
like image 382
Query Master Avatar asked Apr 03 '12 11:04

Query Master


People also ask

What is the correct syntax of foreach loop?

It loops over the array, and each value for the current array element is assigned to $value, and the array pointer is advanced by one to go the next element in the array. Syntax: <? php foreach (array as $value){ //code to be executed; } ?>

How does foreach loop work in JavaScript?

The forEach method passes a callback function for each element of an array together with the following parameters: Current Value (required) - The value of the current array element. Index (optional) - The current element's index number. Array (optional) - The array object to which the current element belongs.

What is continue in foreach PHP?

continue is used within looping structures to skip the rest of the current loop iteration and continue execution at the condition evaluation and then the beginning of the next iteration.


1 Answers

Try this:

<?php
$i=0;    
foreach($videoEntries as $data){
$i++;
?>
    <div class="item-main">
        <div class="item">
        <a href="javascript:;" onclick="ratePopup(2)" title="<?php echo $data->video_name;?>">
        <div class="overlaid"></div>
        <img src="<?php echo $image_url;?>"  width="93" height="89"/>
        </a>
        </div>
        <p title="Trailer Name"><strong><?php echo $data->video_name;?></strong></p>
        <p title="Released Date"><?php echo $data->video_released_date;?></p>
    </div>
<?php 
    if($i == 5){
        echo "<br clear = 'all'>";  
        $i=0;
    }
}
?>
like image 66
web-nomad Avatar answered Oct 25 '22 12:10

web-nomad