Im creating a REST API for the IBM Omnifind Enterprise search engine.
I am able to query and get the result of the search and the paging works perfectly. But the problem is that it generates all the number of pages at once. i.e. if there are 19 pages with 10 result on each page it shows the paging link all at once as
"Previous 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 Next"
I dnt want it to be displayed in this way. I want it to work like the way it works on the Yahoo search, meaning that on the first page it has the first 10 paging links
" 1 2 3 4 5 6 7 8 9 10 Next" and when you click on 10 it then moves 5 links ahead and display them, i.e "Previous 6 7 8 9 10 11 12 13 14 15 Next" and if u again click on the last paging link (15 in this case) it again moves 5 links ahead and displays them. There is a CONSTANT number of paging links (5).
I have googled a lot, but most of the paging are based on mysql.
Here is the code that i have right now that prints the whole paging links at once
function getdata($numHits, $limit, $page)
{
$numHits = (int) $numHits;
$limit = max((int) $limit, 1);
$page = (int) $page;
$numPages = ceil($numHits / $limit);
$page = max($page, 1);
$page = min($page, $numPages);
$offset = ($page - 1) * $limit;
$ret = new stdClass;
$ret->offset = $offset;
$ret->limit = $limit;
$ret->numPages = $numPages;
$ret->page = $page;
return $ret;
}
$pager = getdata($total,$limit,$page);
$offset = $pager->offset;
$limit = $pager->limit;
$page = $pager->page;
if ($page == 1)
echo "<td><br><br>Previous</td>";
else {$prevpage = $page - 1;
echo "<td><br><br><a href=\"$_SERVER[’PHP_SELF’]?start=$start&query=$query&page=$prevpage\">Previous</a></td>"; }
for ($i = 1; $i<=$pager->numPages; $i++)
{ echo " ";
if ($i == $pager->page)
echo "<td><br><br>$i</td>";
elseif ($i != $pager->page)
{ $sno=$i-1;
$start=$sno*10;
echo "<td><br><br><a href=\"$_SERVER[’PHP_SELF’]?start=$start&query=$query&page=$i\">$i</a></td>"; }}
if ($page == $pager->numPages) // this is the last page - there is no next page
echo "<td><br><br>Next</td>";
else { $nextpage = $page + 1;
echo "<td><br><br> <a href=\"$_SERVER[’PHP_SELF’]?start=$start&query=$query&page=$nextpage\">Next</a></td>";
}[/I]
I thought of using a filecounter ($fc) in the for loop, but it doesnt work and then if i go that way then there's an additional GET variable that i will have to handle.
Any help wud be much appreciated.
Thanx in advance.