Insert tr after every third loop
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. 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. $i=0; while(guard()){ if($i % 3 == 0){ //ploing } $i++ } This