When I do a page number script it's generally something like this:
$perpage = 10;
$query = get the id of every row in the table;
$total = num_rows in $query;
$pages = ceil ($total / $perpage);
$pagenum = $_GET['page'];
$start = ($pagenum - 1) * $perpage;
$query = 'select limit ' . $start . ',' . $perpage;
$result = mysql_query ($query);
// and the rest is history
It looks like you've rigged yours up a bit differently and to be perfectly honest I'm having a tiny bit of trouble following it. 🙁 You'll have to excuse me, it's always hard to read someone elses code, haha.
I hope this helps. 🙂