問題描述
我正在用 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的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!