It is probably a problem with an HTML table or something. It would most likely be a problem with the HTML on your page and not the PHP. If you can show the HTML source code of the page that would be the easiest way to help you determine and correct the problem.
could also be fixed with php however, have it where it just spits out 1-20, then the closer you get to 20 it starts adding 21 22 ect while taking away 1 2 3, just have a beginning and end permanant link