How to paginate a custom page template with custom database tables

How to paginate a custom page template with custom database tables