Jump to content

wrap a div around every 4 data


Cultureshock

Recommended Posts

same code works perfectly fine for me? did you update the counter?

//while loop stuff above
$counter++;
}//end while

 

sorry forgot to put that, but thought it was obvious

 

btw you may want to set $counter to 1 instead of 0. 0%4 is 0, so the first time the loop runs it will do the //do something every 4 code

<?php
$counter = 0;
while (your statement here) {
   if ($counter % 4 == 0){
      echo "<div>\n";
   }
   $counter++;
   //echo "\t$counter\n";
   echo "your data";
   if ($counter % 4 == 0){
      echo "</div>\n";
   }
}
if ($counter % 4 != 0){
   echo "</div>\n";
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.