$numeropagina=($numerocommento%$numerocommentiperp agina)+1;

nel tuo esempio

2=(62%50)+1;