每第三个循环后插入 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
为什么不能使用模数?只需在某处添加一个计数器,如果它命中
% 3 == 0
则重置计数器并执行您的操作。您可能需要为第一个和最后一个以及类似的东西做一些额外的 if ,但是没有理由不使用一段时间的模数。
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.
此代码将关闭所有额外的行:
This code will close any extra rows:
我还没有测试代码,但逻辑应该有效:
I haven't tested the code, but the logic should work: