如何在foreach循环中每5次迭代之后定义html标记 [英] how to define html tag after each 5 iteration in foreach loop

查看:261
本文介绍了如何在foreach循环中每5次迭代之后定义html标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想知道如何定义HTML标记< br清除=所有> 在foreach循环中每5次迭代后,这里是我的代码

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'>";    
    }
}
?>

结果必需或有帮助的肯定是appricicated

Result Required or helps are definitely appricicated

12345
<br clear="all">
678910
<br clear="all">


推荐答案

试试这个:

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;
    }
}
?>

这篇关于如何在foreach循环中每5次迭代之后定义html标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆