It is not very clear what you are trying to do, but if what you want is to display data to the user and you have too much data, than you should use paging/pagination.
This is the process roughly:
- You need to read a portion of the data (lets say 100 records) and display it to the user in page one.
- you have buttons that enable the user to move to other page.
- on click, you send an ajax request with the pressed number and you know that you need pressed number * 100 to ((pressed number *100) + 100)
for example:
- first page displays rows 0-100, user clicks next you get rows 100-200 and display them.
- first page displays rows 0-100, user clicks number 4, you get rows 400 - 500 (4*100 to ((4*100) + 100)).