as we don't have data to go with the example, we need you to tell us what it's doing wrong, or what the error is for us to be able to help. Also use of [ code=PHP] [ /code] tags around code helps readability.

For building pagination scripts, I would recommend using Javascript + Jquery.
Create an array in PHP that holds all the info for all the pages.
And loop through that array in Javascript when a user clicks next.
If you need help with the code, send me a PM.