每隔三个循环后插入tr [英] Insert tr after every third loop

查看:109
本文介绍了每隔三个循环后插入tr的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用PHP创建一个论坛。我必须在表格中显示所有论坛类别,为此,我使用了while循环。但是,我想在每个表行中只有3个td。为了遍历类别,我在查询中使用while循环,所以我认为我不能在这里使用模数。

I'm making a forum in PHP. I have to display all forum categories in a table, and to do so, I have used a while loop. However, I want to have only 3 td's in every table row. To loop through the categories, I'm using a while loop with the query, so I don't think I can use modulus here.

推荐答案

为什么不能使用模数?只需在某处添加一个计数器,如果它点击%3 == 0 重置计数器并做你的东西。

Why can't you use modulus? Just add a counter somewhere, and if it hits % 3 == 0 reset the counter and do your stuff.

你可能需要做一些额外的,如果是第一个和最后一个和类似的东西,但没有理由不使用模数一段时间。

You might need to do some extra if's for first and last and stuff like that, but there is no reason not to use a modulo with a while.

$i=0;
while(guard()){
    if($i % 3 == 0){
       //ploing
    }
 $i++
}

这篇关于每隔三个循环后插入tr的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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