PHP - Loop thru recordset and fire event each n rows
- by Luciano
I'm looking for the right logic to loop thru a recordset and fire an event each n times.
Searching on Google i've found some discussion on similar situations, but it seems that solutions don't fits my needs.
Let's say i have a recordset of 22 rows. I want to loop thru each row and launch a function on the 4th, the 8th, the 12th and so on...
Using the modulus operator as shown in this answer, if($i % 4 == 0), i get the event fired each 4 rows, but 22 its not a multiple of 4 so the event is fired till the 20th row and then nothing. Maybe i need to make a division counting rows in 'excess'?
Since the recordset will be between 50 and 200 rows i think its not necessary run multiple query of 4 rows, am I wrong?
Thanks in advance!