Insert tr after every third loop(每第三个循环后插入 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:每第三个循环后插入 tr


- 覆盖 Magento 社区模块控制器的问题 2022-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- 如何在 Symfony2 中正确使用 webSockets 2021-01-01
- 如何从数据库中获取数据以在 laravel 中查看页面? 2022-01-01
- 如何使用 Google API 在团队云端硬盘中创建文件夹? 2022-01-01
- 使用 GD 和 libjpeg 支持编译 PHP 2022-01-01
- Laravel 5:Model.php 中的 MassAssignmentException 2021-01-01
- PHP - if 语句中的倒序 2021-01-01
- PHP foreach() 与数组中的数组? 2022-01-01
- openssl_digest vs hash vs hash_hmac?盐与盐的区别HMAC? 2022-01-01