/ Published in: PHP

Simple loop for adding header and footer avery n times in loop. Useful for printing tables.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/* how many items to loop: */ $count = 6; /* how many items in row: */ $n = 3; for( $i=1; $i<=$count; $i++ ) { // add header if( $i%$n === 1 || $i === 1 ) { echo 'header<br>'; } // echo content echo "content no. $i<br>"; // add footer if( $i%$n === 0 || $i === $count ) { echo 'footer<br>'; } }
Comments
