Paging and limiting amount of links

Hi all!

Got a bit of a question with paging in php. Basically, I’m pulling data out of a mySQL database and through PHP I’m generating pages and links etc. Through a for loop so that for each page I have ‘1, 2, 3, 4, 5’ and so on.

The thing I need a bit of help with is that I need to limit the amount of page links so that that if I have, say 50 pages it shows something like this:

1, 2, 3 …49, 50

If that makes sense? Just so I don’t have a load of links on my page, to improve the UI. I know it can be done, it’s even on this forum for threads.

If some one can help point me in the right direction that would be great. I’ve tried googling and searching the forums on the subject, but I can’t seem to find anything.

Thanks.