Paginating MySQL data in loaded php script

Paginating MySQL data in loaded php script

I have a php script which contains various links which get handled by a jQuery function which in turn passes parameters to and loads another php script.  The php script that gets loaded queries a large MySQL database and returns a set of results in an HTML table.  Where there is more than 1 page of results the php script provides page numbers which can be clicked on to bring up further pages of results.  Where there are more than 20 pages a small algorithm displays an abbreviated set of page numbers, e.g.

 1 2 3 4 5 .. 37

Each page has an anchor around it that looks something like this:

  1. <a href='subgenre.php?sg=genre&pg=$pagenum'>

This obviously worked fine when the script was running on its own but now it's being loaded using jQuery it's preumably of no use.  Can anyone suggest a way of tackling the problem, I did take a look at various pagination plugins but they didn't seem to be what I was looking for based on what I've said above.

Thanks in advance for any help or guidance.

Ian
__