Improve your database routines. You will probably want to use a temporary table to help flatten and normalize your multi-dimentional data before attempting to paginate it. You will need to keep track of what page you're on and how big each page is,
If you're using mysql, use an auto generated id column to specify where you start AND id > 300
then add LIMIT 100
to say where you end.
On oracle it would be AND RowNum between 300 and 400
.
Your other option is using your recursive function to build a flat list of id's and store it in the session, and then run your pagination routine over that.
Your other-other option is to rewrite the recusion into a stack-and-loop structure so you know how far you've gone as you're going through it, specifying a start point for this page, running through it until you hit the start counter, emit data until you hit the end marker, and return.
The worst option, of course, would be to simply use globals to indicate how many things you have tried to print out and put an if ($count >= $start && $count <= $end)
around the echo
statements. Don't do that. but it would be very simple to do and probably work without thinking about it very hard and be horribly inefficient.