I am using this pagination script given below. The problem is that it gives the continuous count of the pages. Say for example if there are 10 pages it gives out numbers 1 2 3 4 5 6 7 8 9 10
(all clickable to respective pages). What I want is to break pagination count after 5. It should display 1 2 3 4 5.......9 10
. Then when I click on page number 5 it should hide 1 and display 6 as 2 3 4 5 6....9 10
. Please help me.
$start = 0;
$limit = 1;
if(isset($_GET['id'])){
$id = (!empty($_GET['id']))?$_GET['id']:null;
$start = ($id-1)*$limit;
}else{
$id = null;
}
$stmt = $pdo->prepare("SELECT ad_id, ad_description, ad_url, ad_memclicks, ad_visclicks, ad_status, avc_clicks FROM ads
LEFT JOIN ads_viewed_cost ON ads.ad_clicks = ads_viewed_cost.avc_id
WHERE ad_user = :user LIMIT $start, $limit");
$stmt-> bindValue(':user', $sessionid);
$stmt-> execute();
$count = $pdo->prepare("SELECT COUNT(*) as cnt FROM ads LEFT JOIN ads_viewed_cost ON ads.ad_clicks = ads_viewed_cost.avc_id WHERE ad_user = :user");
$count-> bindValue(':user', $sessionid);
$count-> execute();
$rf = $count->fetch();
$rows = $rf['cnt'];
$total = ceil($rows/$limit);
if($id>1){
echo "<span class='pre'><a href='?id=".($id-1)."' class='button'>PREVIOUS</a></span>";
}
if($id!=$total){
echo "<span class='next'><a href='?id=".($id+1)."' class='button'>NEXT</a></span>";
}
echo "<ul class='pagination'>";
for($i=1; $i<=$total; $i++){
if($i == $id){
echo "<li class='current'>".$i."</li>";
}else{
echo "<li><a href='?id=".$i."'>".$i."</a></li>";
}
}
echo "</ul>";