Added function to generate pagination for mysql results

Tried to make this universal for use elsewhere.