問(wèn)題描述
我正在用 PHP 創(chuàng)建一個(gè)論壇.我必須在表格中顯示所有論壇類(lèi)別,為此,我使用了一個(gè) while 循環(huán).但是,我希望每個(gè)表格行中只有 3 個(gè) td.為了遍歷類(lèi)別,我在查詢(xún)中使用了 while 循環(huán),所以我認(rèn)為我不能在這里使用模數(shù).
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.
推薦答案
為什么不能使用模數(shù)?只需在某處添加一個(gè)計(jì)數(shù)器,如果它命中 % 3 == 0
重置計(jì)數(shù)器并執(zhí)行您的操作.
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 之類(lèi)的事情,但沒(méi)有理由不使用模數(shù) 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++
}
這篇關(guān)于每第三個(gè)循環(huán)后插入 tr的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!