Hi, I am running a script on my website, currently we have simple pagination like it doesn't show how many total pages we have and when clicked the last page i.e. 12 in this case here is how it look I want it like Here is what we have in pagination class for now. <? class pagination { public function __construct() { } public function calculate_pages($total_rows, $rows_per_page, $page_num) { $arr = array(); // calculate last page $last_page = ceil($total_rows / $rows_per_page); // make sure we are within limits $page_num = (int) $page_num; if ($page_num < 1) { $page_num = 1; } elseif ($page_num > $last_page) { $page_num = $last_page; } $upto = ($page_num - 1) * $rows_per_page; $arr['limit'] = 'LIMIT '.$upto.',' .$rows_per_page; $arr['current'] = $page_num; if ($page_num == 1) $arr['previous'] = $page_num; else $arr['previous'] = $page_num - 1; if ($page_num == $last_page) $arr['next'] = $last_page; else $arr['next'] = $page_num + 1; $arr['last'] = $last_page; $arr['info'] = 'Page ('.$page_num.' of '.$last_page.')'; $arr['pages'] = $this->get_surrounding_pages($page_num, $last_page, $arr['next']); return $arr; } function get_surrounding_pages($page_num, $last_page, $next) { $arr = array(); $show = 12; // how many boxes // at first if ($page_num == 1) { // case of 1 page only if ($next == $page_num) return array(1); for ($i = 0; $i < $show; $i++) { if ($i == $last_page) break; array_push($arr, $i + 1); } return $arr; } // at last if ($page_num == $last_page) { $start = $last_page - $show; if ($start < 1) $start = 0; for ($i = $start; $i < $last_page; $i++) { array_push($arr, $i + 1); } return $arr; } // at middle $start = $page_num - $show; if ($start < 1) $start = 0; for ($i = $start; $i < $page_num; $i++) { array_push($arr, $i + 1); } for ($i = ($page_num + 1); $i < ($page_num + $show); $i++) { if ($i == ($last_page + 1)) break; array_push($arr, $i); } return $arr; } } ?> PHP: And on page where we are displaying the pagination have the following code {foreach from=$pagination.pages item=page} PHP: Can anybody please sort this thing out for me. I am willing to pay a reasonable fees for this. -Regards.
Try to use this pagination class. Not sure it will work. But give it a try. http://www.phpclasses.org/package/3784-PHP-Show-links-to-browse-MySQL-query-result-listings.html
I could fix this for you for $50 as it will require a lot of rejigging of the code. PM if interested.
Here you go. Besides fixing your code I've took the permission to show only 11 pages at once. PM what the reward is please. <? class pagination { public function __construct() { } public function calculate_pages($total_rows, $rows_per_page, $page_num) { $arr = array(); // calculate last page $last_page = ceil($total_rows / $rows_per_page); // make sure we are within limits $page_num = (int) $page_num; if ($page_num < 1) { $page_num = 1; } elseif ($page_num > $last_page) { $page_num = $last_page; } $upto = ($page_num - 1) * $rows_per_page; $arr['limit'] = 'LIMIT '.$upto.',' .$rows_per_page; $arr['current'] = $page_num; if ($page_num == 1) $arr['previous'] = $page_num; else $arr['previous'] = $page_num - 1; if ($page_num == $last_page) $arr['next'] = $last_page; else $arr['next'] = $page_num + 1; $arr['last'] = $last_page; $arr['info'] = 'Page ('.$page_num.' of '.$last_page.')'; $arr['pages'] = $this->get_surrounding_pages($page_num, $last_page, $arr['next']); return $arr; } function get_surrounding_pages($page_num, $last_page, $next) { $arr = array(); $show = 11; // how many boxes $left = $right = 5; // at first if ($page_num == 1) { // case of 1 page only if ($next == $page_num) return array(1); for ($i = 0; $i < $show; $i++) { if ($i == $last_page) break; array_push($arr, $i + 1); } return $arr; } // at last if ($page_num == $last_page) { $start = $last_page - $show; if ($start < 1) $start = 0; for ($i = $start; $i < $last_page; $i++) { array_push($arr, $i + 1); } return $arr; } // at middle $lrest = $rrest = 0; $start = 0; $end = $last_page; if($page_num - $left >= 0) { $start = $page_num - $left; } else { $lrest = $left - $page_num; } if($page_num + $right <= $last_page) { $end = $page_num + $right; } else { $rrest = ($page_num + $right) - $last_page; } if($rrest > 0) $start -= $rrest; if($lrest > 0) $end += $lrest; for ($i = $start-1; $i < $end; $i++) { array_push($arr, $i + 1); } return $arr; } } ?> PHP:
Show me the full part of the template related to pagination please... the one that includes : {foreach from=$pagination.pages item=page}
How about this : <? class pagination { public function __construct() { } public function calculate_pages($total_rows, $rows_per_page, $page_num) { $arr = array(); // calculate last page $last_page = ceil($total_rows / $rows_per_page); // make sure we are within limits $page_num = (int) $page_num; if ($page_num < 1) { $page_num = 1; } elseif ($page_num > $last_page) { $page_num = $last_page; } $upto = ($page_num - 1) * $rows_per_page; $arr['limit'] = 'LIMIT '.$upto.',' .$rows_per_page; $arr['current'] = $page_num; if ($page_num == 1) $arr['previous'] = $page_num; else $arr['previous'] = $page_num - 1; if ($page_num == $last_page) $arr['next'] = $last_page; else $arr['next'] = $page_num + 1; $arr['last'] = $last_page; $arr['info'] = 'Page ('.$page_num.' of '.$last_page.')'; $arr['pages'] = $this->get_surrounding_pages($page_num, $last_page, $arr['next']); return $arr; } function get_surrounding_pages($page_num, $last_page, $next) { $arr = array(); $show = 5; // how many boxes $left = $right = 2; // at first if ($page_num == 1) { // case of 1 page only if ($next == $page_num) return array(1); for ($i = 0; $i < $show; $i++) { if ($i == $last_page) break; array_push($arr, $i + 1); } return $arr; } // at last if ($page_num == $last_page) { $start = $last_page - $show; if ($start < 1) $start = 0; for ($i = $start; $i < $last_page; $i++) { array_push($arr, $i + 1); } return $arr; } // at middle $lrest = $rrest = 0; $start = 0; $end = $last_page; if($page_num - $left >= 0) { $start = $page_num - $left; } else { $lrest = $left - $page_num; } if($page_num + $right <= $last_page) { $end = $page_num + $right; } else { $rrest = ($page_num + $right) - $last_page; } if($rrest > 0) $start -= $rrest; if($lrest > 0) $end += $lrest; for ($i = $start-1; $i < $end; $i++) { array_push($arr, $i + 1); } return $arr; } } ?> PHP: Drop me a screenshot pls.
No changes same as it was before. But one more thing i have noticed there is some coding for pagination in one another file here is what we have
Dude did you change the template to what I gave you : <div style="border : 1px solid black;">{$pagination.info}</div> {if $page > 1} <a href="/sms-messages/{$category.category_id}/{$category.name_url}/1" style="border: 1px solid #000000; padding: 0px 5px; color: #000000;">First «</a> {/if} {if $page > 1} <a href="/sms-messages/{$category.category_id}/{$category.name_url}/{$pagination.previous}" {if $pagination.current != $page}style="border: 1px solid #000000; padding: 0px 5px; color: #000000;"{/if}>«</a> {/if} {foreach from=$pagination.pages item=page} <a href="/sms-messages/{$category.category_id}/{$category.name_url}{if $page != 1}/{$page}{/if}" {if $pagination.current != $page}style="border: 1px solid #000000; padding: 0px 5px; color: #000000;"{/if}>{$page}</a> {/foreach} {if $page < $pagination.last} <a href="/sms-messages/{$category.category_id}/{$category.name_url}/{$pagination.next}" {if $pagination.current != $page}style="border: 1px solid #000000; padding: 0px 5px; color: #000000;"{/if}>»</a> {/if} {if $page < $pagination.last} <a href="/sms-messages/{$category.category_id}/{$category.name_url}/{$pagination.last}" style="border: 1px solid #000000; padding: 0px 5px; color: #000000;">Last »</a> {/if}