msaz87 Posted November 12, 2009 Share Posted November 12, 2009 I'm looking to see if there's a way you can have a statement that says "after X items displayed in a loop, display this code"... so if the loop was going to pull 10 things out of a DB and I wanted something display after every 4 items, it would just go: --DB ENTRY 1-- --DB ENTRY 2-- --DB ENTRY 3-- --DB ENTRY 4-- --"CODE"-- --DB ENTRY 5-- --DB ENTRY 6-- --DB ENTRY 7-- --DB ENTRY 8-- --"CODE"-- --DB ENTRY 9-- --DB ENTRY 10-- Thanks for the help! Link to comment https://forums.phpfreaks.com/topic/181311-way-to-insert-code-after-so-many-items-display-in-a-loop/ Share on other sites More sharing options...
mikesta707 Posted November 12, 2009 Share Posted November 12, 2009 $counter = 0; while (condition){ //stuff if ($counter % 4 == 0){ //do somethign every 4th time } $counter++; } untested but should work. you may need to set counter to 1 Link to comment https://forums.phpfreaks.com/topic/181311-way-to-insert-code-after-so-many-items-display-in-a-loop/#findComment-956469 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.