Hello I'm using Ajax and Php to show pagination
In my code First and Previous link is working but Next and Last link is not working I mean this Next and Last link is going to last page. It's should be go to last page when I press Last link but If press Next link it's also go to last page. Next link should go to Next page. Can you tell me why ?
Here is my php code :
function paginate_function($item_per_page, $current_page, $total_records, $total_pages)
{
$pagination = '';
if($total_pages > 0 && $total_pages != 1 && $current_page <= $total_pages){ //verify total pages and current page number
$pagination .= '<ul class="pagination">';
$right_links = $current_page + 15;
$previous = $current_page - 1; //previous link
$next = $current_page + 1; //next link
$first_link = true; //boolean var to decide our first link
if($current_page > 1){
$previous_link = ($previous==0)?1:$previous;
$pagination .= '<li class="first"><a href="#" data-page="1" title="First">first</a></li>'; //first link
$pagination .= '<li><a href="#" data-page="'.$previous_link.'" title="Previous">prev</a></li>'; //previous link
for($i = ($current_page-2); $i < $current_page; $i++){ //Create left-hand side links
if($i > 0){
$pagination .= '<li><a href="#" data-page="'.$i.'" title="Page'.$i.'">'.$i.'</a></li>';
}
}
$first_link = false; //set first link to false
}
if($first_link){ //if current active page is first link
$pagination .= '<li class="first active">'.$current_page.'</li>';
}elseif($current_page == $total_pages){ //if it's the last active link
$pagination .= '<li class="last active">'.$current_page.'</li>';
}else{ //regular current link
$pagination .= '<li class="active">'.$current_page.'</li>';
}
for($i = $current_page+1; $i < $right_links ; $i++){ //create right-hand side links
if($i<=$total_pages){
$pagination .= '<li><a href="#" data-page="'.$i.'" title="Page '.$i.'">'.$i.'</a></li>';
}
}
if($current_page < $total_pages){
$next_link = ($i > $total_pages)? $total_pages : $i;
$pagination .= '<li><a href="#" data-page="'.$next_link.'" title="Next">Next</a></li>'; //next link
$pagination .= '<li class="last"><a href="#" data-page="'.$total_pages.'" title="Last">Last</a></li>'; //last link
}
$pagination .= '</ul>';
}
return $pagination; //return pagination links
}
You help is very much appreciated :)
wow. I just solved my issue. it's should be variable $next instead of $next_link on Next Link. Thank You.