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

查看:30
本文介绍了每第三个循环后插入 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.

您可能需要为 first 和 last 做一些额外的 if's for first 和 last 之类的事情,但没有理由不使用模数 with a while.

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天全站免登陆