Since I am trying to learn more about PHP I would like to add Pagination to array's
I have a JSON output that I can read and echo via a foreach. But I am not able to show 10 or 20 records.
I have used the code from this page:
But I miss the place where I can store the echo for the array.
$persons = '[
{"FrstName":"Henry","Middlename":"","LastName":"Walton","Online":true,"DeptId":"4"},
{"FrstName":"Klaus","Middlename":"","LastName":"Mikaelson","Online":true,"DeptId":"2"},
{"FrstName":"Kylo","Middlename":"","LastName":"Ren","Online":false,"DeptId":"4"},
{"FrstName":"Stan","Middlename":"","LastName":"Lee","Online":false,"DeptId":"3"},
{"FrstName":"Kevin","Middlename":"","LastName":"McNally","Online":false,"DeptId":"3"},
{"FrstName":"Katherine","Middlename":"","LastName":"Pierce","Online":false,"DeptId":"2"},
{"FrstName":"Clint","Middlename":"","LastName":"Barton","Online":true,"DeptId":"3"},
{"FrstName":"Avery","Middlename":"","LastName":"Walton","Online":true,"DeptId":"4"},
{"FrstName":"Peter","Middlename":"","LastName":"Kap","Online":true,"DeptId":"2"},
{"FrstName":"Denzo","Middlename":"","LastName":"Falc","Online":false,"DeptId":"4"},
{"FrstName":"Eveline","Middlename":"","LastName":"Benzel","Online":false,"DeptId":"3"},
{"FrstName":"Bill","Middlename":"","LastName":"Libuz","Online":false,"DeptId":"3"},
{"FrstName":"April","Middlename":"","LastName":"Gonzo","Online":false,"DeptId":"2"},
{"FrstName":"Harry","Middlename":"","LastName":"Geraldson","Online":true,"DeptId":"3"},
{"FrstName":"Heraldson","Middlename":"","LastName":"McGree","Online":false,"DeptId":"3"}
{"FrstName":"Abraham","Middlename":"","LastName":"Retz","Online":true,"DeptId":"4"},
{"FrstName":"June","Middlename":"","LastName":"Pharee","Online":true,"DeptId":"2"},
{"FrstName":"Anthony","Middlename":"","LastName":"Gonzales","Online":false,"DeptId":"4"},
{"FrstName":"Billy","Middlename":"","LastName":"Scott","Online":false,"DeptId":"3"},
{"FrstName":"Anika","Middlename":"","LastName":"Rose","Online":false,"DeptId":"3"},
{"FrstName":"Kristen","Middlename":"","LastName":"Fontana","Online":false,"DeptId":"2"},
{"FrstName":"Olivia","Middlename":"","LastName":"Menzel","Online":true,"DeptId":"3"},
{"FrstName":"Mark","Middlename":"van","LastName":"Gad","Online":false,"DeptId":"3"}
{"FrstName":"Hope","Middlename":"van","LastName":"Dyne","Online":false,"DeptId":"3"}
]';
$page = ! empty( $_GET['page'] ) ? (int) $_GET['page'] : 1;
$total = count( $persons ); //total items in array
$limit = 10; //per page
$totalPages = ceil( $total/ $limit ); //calculate total pages
$page = max($page, 1); //get 1 page when $_GET['page'] <= 0
$page = min($page, $totalPages); //get last page when $_GET['page'] > $totalPages
$offset = ($page - 1) * $limit;
if( $offset < 0 ) $offset = 0;
$yourDataArray = array_slice( $persons, $offset, $limit );
$link = 'index.php?page=%d';
$pagerContainer = '<div style="width: 300px;">';
if( $totalPages != 0 )
{
if( $page == 1 )
{
$pagerContainer .= '';
}
else
{
$pagerContainer .= sprintf( ' « prev page', $page - 1 );
}
$pagerContainer .= ' <span> page <strong>' . $page . '</strong> from ' . $totalPages . '</span>';
if( $page == $totalPages )
{
$pagerContainer .= '';
}
else
{
$pagerContainer .= sprintf( ' next page » ', $page + 1 );
}
}
$pagerContainer .= '</div>';
echo $pagerContainer;
I would like to know how I can fix this to use pagination for my array.
You need to json_decode() your JSON first to access array methods (count(), array_slice()). Also, your JSON data was invalid, missing some commas, fixed that.
<?php
$persons = '[
{"FrstName":"Henry","Middlename":"","LastName":"Walton","Online":true,"DeptId":"4"},
{"FrstName":"Klaus","Middlename":"","LastName":"Mikaelson","Online":true,"DeptId":"2"},
{"FrstName":"Kylo","Middlename":"","LastName":"Ren","Online":false,"DeptId":"4"},
{"FrstName":"Stan","Middlename":"","LastName":"Lee","Online":false,"DeptId":"3"},
{"FrstName":"Kevin","Middlename":"","LastName":"McNally","Online":false,"DeptId":"3"},
{"FrstName":"Katherine","Middlename":"","LastName":"Pierce","Online":false,"DeptId":"2"},
{"FrstName":"Clint","Middlename":"","LastName":"Barton","Online":true,"DeptId":"3"},
{"FrstName":"Avery","Middlename":"","LastName":"Walton","Online":true,"DeptId":"4"},
{"FrstName":"Peter","Middlename":"","LastName":"Kap","Online":true,"DeptId":"2"},
{"FrstName":"Denzo","Middlename":"","LastName":"Falc","Online":false,"DeptId":"4"},
{"FrstName":"Eveline","Middlename":"","LastName":"Benzel","Online":false,"DeptId":"3"},
{"FrstName":"Bill","Middlename":"","LastName":"Libuz","Online":false,"DeptId":"3"},
{"FrstName":"April","Middlename":"","LastName":"Gonzo","Online":false,"DeptId":"2"},
{"FrstName":"Harry","Middlename":"","LastName":"Geraldson","Online":true,"DeptId":"3"},
{"FrstName":"Heraldson","Middlename":"","LastName":"McGree","Online":false,"DeptId":"3"},
{"FrstName":"Abraham","Middlename":"","LastName":"Retz","Online":true,"DeptId":"4"},
{"FrstName":"June","Middlename":"","LastName":"Pharee","Online":true,"DeptId":"2"},
{"FrstName":"Anthony","Middlename":"","LastName":"Gonzales","Online":false,"DeptId":"4"},
{"FrstName":"Billy","Middlename":"","LastName":"Scott","Online":false,"DeptId":"3"},
{"FrstName":"Anika","Middlename":"","LastName":"Rose","Online":false,"DeptId":"3"},
{"FrstName":"Kristen","Middlename":"","LastName":"Fontana","Online":false,"DeptId":"2"},
{"FrstName":"Olivia","Middlename":"","LastName":"Menzel","Online":true,"DeptId":"3"},
{"FrstName":"Mark","Middlename":"van","LastName":"Gad","Online":false,"DeptId":"3"},
{"FrstName":"Hope","Middlename":"van","LastName":"Dyne","Online":false,"DeptId":"3"}
]';
// Make the JSON an array, so count() and array_slice() work
$persons = json_decode($persons, true);
$page = ! empty( $_GET['page'] ) ? (int) $_GET['page'] : 1;
$total = count( $persons ); //total items in array
// $limit = 10; //per page
// Set limit to 3 for testing:
$limit = 3;
$totalPages = ceil( $total/ $limit ); //calculate total pages
$page = max($page, 1); //get 1 page when $_GET['page'] <= 0
$page = min($page, $totalPages); //get last page when $_GET['page'] > $totalPages
// Uncomment this for testing
// $page = 2;
$offset = ($page - 1) * $limit;
if( $offset < 0 ) $offset = 0;
$yourDataArray = array_slice( $persons, $offset, $limit );
$link = 'index.php?page=%d';
$pagerContainer = '<div style="width: 300px;">';
if( $totalPages != 0 )
{
if( $page == 1 )
{
$pagerContainer .= '';
}
else
{
$pagerContainer .= sprintf( ' « prev page', $page - 1 );
}
$pagerContainer .= ' <span> page <strong>' . $page . '</strong> from ' . $totalPages . '</span>';
if( $page == $totalPages )
{
$pagerContainer .= '';
}
else
{
$pagerContainer .= sprintf( ' next page » ', $page + 1 );
}
}
$pagerContainer .= '</div>';
echo $pagerContainer;
foreach($yourDataArray as $person) {
echo "\n";
echo "First name: " . $person['FrstName'];
echo " - Middle name: " . $person['Middlename'];
echo " - Last name: " . $person['LastName'];
echo " - Online: " . $person['Online'];
echo " - Dept: " . $person['DeptId'];
}
https://3v4l.org/8hR84
Related
I am a new developer. This code has used form plugin for showing rating average and its working well. But its showing rating above of WP content. I want to show rating on my several specific location of blog page and single page. How can I do that?
add_filter( 'the_content', 'ci_comment_rating_display_average_rating' );
function ci_comment_rating_display_average_rating( ) {
global $post;
if ( false === ci_comment_rating_get_average_ratings( $post->ID ) ) {
return $content;
}
$stars = '';
$average = ci_comment_rating_get_average_ratings( $post->ID );
for ( $i = 1; $i <= $average + 1; $i++ ) {
$width = intval( $i - $average > 0 ? 20 - ( ( $i - $average ) * 20 ) : 20 );
if ( 0 === $width ) {
continue;
}
$stars .= '<span style="overflow:hidden; width:' . $width . 'px" class="dashicons dashicons-star-filled"></span>';
if ( $i - $average > 0 ) {
$stars .= '<span style="overflow:hidden; position:relative; left:-' . $width .'px;" class="dashicons dashicons-star-empty"></span>';
}
}
$custom_content = '<p class="average-rating">This post\'s average rating is:-- ' . $average .' ' . $stars .'</p>';
$custom_content .= $content;
return $custom_content;
}
I have this array which contain around 1000 records. I want to display 20 array records per page.
$list=array(
array([title]=>"sony", [description]=>"camera"),
array([title]=>"sony", [description]=>"mobiles"),
array([title]=>"lenovo", [description]=>"laptop"),
array([title]=>"lenovo", [description]=>"mobiles")
);
I have used the following code for pagination. It is giving me a long row for pagination. Can someone help me to include previous and next code to my existing code so that my pagination will look good.
$page = isset($_REQUEST['page']) && $_REQUEST['page'] > 0 ? $_REQUEST['page'] : 1;
function display($list, $page = 1)
{
$start = ($page - 1) * 2;
$list = array_slice($list, $start, 15);
foreach ($list as $key => $val) {
echo $val['title'] . '<br/>';
echo $val['description'] . '<br/>';
echo "<br>";
}} $len = count($list);
$pages = ceil($len / 2);
if ($page > $pages or $page < 1)
{
echo 'page not found';
}
else
{
display($list, $page);
for ($i = 1 ; $i <= $pages ; $i++)
{
$current = ($i == $page) ? TRUE : FALSE;
if ($current) {
echo '<b>' . $i . '</b>';
}
else
{
?>
<?php echo $i;?>
<?php
}
}
}
Here's an example with the data array from your question.
The example
The page size is assumed to be 2 (20 in your question).
The size of the data array does not matter.
The start parameter is provided (as in your example) thru a GET parameter http://localhost/flipkart-api/fkt_offer.php?…start=index_or_page. This parameter is available in the script as $_GET['start'].
The previous and next start indices are to be calculated ($start +/- $maxpage, etc.).
To keep this example simple, I took the start index, not the page number, as parameter. But you also could use a page number and calculate the index, of course.
For the reason of brevity I omitted error checking ("what if no more items", etc.).
Code:
<?php
// The data array
$list=array(
array('title'=>"sony", 'description'=>"camera"),
array('title'=>"sony", 'description'=>"mobiles"),
array('title'=>"lenovo", 'description'=>"laptop"),
array('title'=>"lenovo", 'description'=>"mobiles")
);
// Evaluate URL
$proto = ((isset($_SERVER["HTTPS"])) && (strtoupper($_SERVER["HTTPS"]) == 'ON')) ? "https://" : "http://";
$hname = getenv("SERVER_NAME");
$port = getenv("SERVER_PORT");
if ( (($port==80)&&($proto=='http://')) || (($port==443)&&($proto=='https://')) ) { $port = ''; }
$params = '';
foreach ($_GET as $key=>$value) {
if (strtolower($key)=='start') continue;
$params .= (empty($params)) ? "$key=$value" : "&$key=$value";
}
$url = $proto . $hname . $port. $_SERVER['SCRIPT_NAME'] . '?' . $params;
// Page contents
$last = count($list)-1;
$start = (isset($_GET['start'])) ? intval($_GET['start']) : 0;
if ($start<0) $start = 0; if ($start > $last) $start = $last;
$maxpage = 2;
echo "<p>Start index = $start</p>" . PHP_EOL;
$curpage = 0;
for($xi=$start; $xi<=$last; $xi++) {
if ($curpage >= $maxpage) break;
$curpage++;
echo 'Entry ' . $curpage .
': ' . $list[$xi]['title'] .
' - ' . $list[$xi]['description'] .
'<br />' . PHP_EOL;
}
// Navigation
$prev = $start - $maxpage; if ($prev<0) $prev = 0;
$next = ( ($start+$maxpage) > $last) ? $start : $start + $maxpage;
$prev = ( ($start-$maxpage) < 0) ? 0 : $start - $maxpage;
echo '<p>Previous ';
echo 'Next</p>';
?>
Result (e.g)
Start index = 2
Entry 1: lenovo - laptop
Entry 2: lenovo - mobiles
Previous Next
So i wrote a simple pagination function:
function pagination ( $iTotalItems )
{
if( is_array( $iTotalItems ) )
$totalItems = sizeof ( $iTotalItems );
if( is_int( $iTotalItems ) )
$totalItems = $iTotalItems;
$page = (int)( empty( $_GET['page'] ) ? 1 : $_GET['page'] );
if ($page <= 0) $page = 1;
$itemsPerPage = PAG_PER_PAGE;
$prev = $page - 1;
$next = $page + 1;
$prevlabel = "‹ Prev";
$nextlabel = "Next ›";
$totalPages = ceil( $iTotalItems / $itemsPerPage );
$perPage = $page == 'all' ? $totalItems : $itemsPerPage;
$adjacents = 2;
if( $totalItems > $itemsPerPage )
{
$filler = '';
$NumStart = '';
$NumEnd = '';
$pageNavigation = '<div class="Pagination">'. PHP_EOL;
$previousLink = $prev !== 0 ? "<a href='?p=items&page={$prev}'>{$prevlabel}</a>". PHP_EOL : "<span class='noneLink'>{$prevlabel}</span>". PHP_EOL;
$nextLink = $page < $totalPages ? "<a href='?p=items&page={$next}'>{$nextlabel}</a>". PHP_EOL : "<span class='noneLink'>{$nextlabel}</span>". PHP_EOL;
for( $i = 1; $i < $totalPages + 1; $i++ )
{
if( $i <= 10 ) { $NumStart .= $page == $i ? '<span class="noneLink">'.$i.'</span>' : ''.$i.''. PHP_EOL; }
else { $filler = '...'; }
if( $i > $totalPages - 3 ) {$NumEnd .= $page == $i ? "<span class='noneLink'>{$i}</span>" : "<a href='?p=items&page={$i}'>{$i}</a>". PHP_EOL; }
}
}
return $pageNavigation . $previousLink . $NumStart . $filler . $NumEnd . $nextLink . '</div>';
}
Now it works great and all but Im not sure how to make it change depending on the page. For example: with 40 pages and while on page 1 it looks like this.
‹ Prev 1 2 3 4 5 67 8 9 10 ...38 39 40 Next ›
However, even if im at page.. say 20 it still looks the same.
Whats the best and most simple way to code something like this while on page 1:
1 2 3 4 5 6 7 8 9 … 38 39 40 Next ›
and something like this while on page 15:
‹ Prev 1 2 3 … 11 12 13 14 15 16 17 18 19 … 38 39 40 Next ›
Thanks in advance!
I have two tiny little problems;
1 . I want to add a previous / next button into this code
2 . I want it to only show like max 10 links between previous and next. So if i have 50 numbers/links it will only show 10 of them and not 50 links on the page.
I have searched on the clo
The code works, only need that two options in it.
Can someone help me out? Thank you !
<?php
include 'includes/connection.php';
$per_page = 8;
$pages_query = mysql_query("SELECT COUNT(`id`) FROM `products`");
$pages = ceil(mysql_result($pages_query, 0) / $per_page);
$page = (isset($_GET['page'])) ? (int)$_GET['page'] : 1;
$start = ($page - 1) * $per_page;
$query = mysql_query("SELECT `name` FROM `products` LIMIT $start, $per_page");
while ($query_row = mysql_fetch_assoc($query)) {
echo '<p>', $query_row['name'] ,'</p>';
}
if ($pages >= 1 && $page <= $pages) {
for ($x=1; $x<=$pages; $x++) {
//echo $x, ' ';
echo ($x == $page) ? '<strong>'.$x.'</strong> ' : ''.$x.' ';
}
}else{
header("location:index.php?page=1");
}
?>
First of all, you should, just for good practice, put an "exit;" after the header() call at the end. It doesn't make a difference in this particular script, but keep in mind that any code following a header("Location: ...") call WILL be executed before redirection.
Now to your question, try this (UPDATE: This code has been tested and works.)
<?php
include 'includes/connection.php';
$per_page = 8;
$pages_query = mysql_query("SELECT COUNT(`id`) FROM `products`");
$pages = ceil(mysql_result($pages_query, 0) / $per_page);
$page = (isset($_GET['page'])) ? (int)$_GET['page'] : 1;
$start = ($page - 1) * $per_page;
$query = mysql_query("SELECT `name` FROM `products` LIMIT $start, $per_page");
while ($query_row = mysql_fetch_assoc($query))
{
echo '<p>' . $query_row['name'] . '</p>';
}
// If the requested page is less than 1 or more than the total number of pages
// redirect to the first page
if($pages < 1 || $page > $pages)
{
header('Location: ?page=1');
// end execution of the rest of this script
// it will restart execution after redirection
exit;
}
// If more than one page, show pagination links
if($pages > 1)
{
$html = array();
$html[] = '<strong>';
// if you're on a page greater than 1, show a previous link
$html[] = (($page > 1) ? 'Previous ' : '');
// First page link
$pageFirst = '1';
$html[] = (($page == 1) ? "</strong>{$pageFirst}<strong>" : $pageFirst);
if ($pages > 6)
{
$start_cnt = min(max(1, $page - (6 - 1)), $pages - 6);
$end_cnt = max(min($pages, $page + 4), 8);
$html[] = ($start_cnt > 1) ? '...' : ' ';
for ($i = $start_cnt + 1; $i < $end_cnt; $i++)
{
$html[] = ($i == $page) ? '</strong>' . $i . '<strong>' : '' . $i . '';
if ($i < $end_cnt - 1)
{
$html[] = ' ';
}
}
$html []= ($end_cnt < $pages) ? '...' : ' ';
}
else
{
$html[] = ' ';
for ($i = 2; $i < $pages; $i++)
{
$html[] = ($i == $page) ? '</strong>' . $i . '<strong>' : '' . $i . '';
if ($i < $pages)
{
$html[] = ' ';
}
}
}
// last page link
$pageLast = '' . $pages . '';
$html[] = (($page == $pages) ? "</strong>{$pageLast}<strong>" : $pageLast);
// Show next page link if you're on a page less than the total number of pages
$html[] = ($page < $pages) ? ' Next' : '';
// If you're not on the last page, show a next link
$html[] = '</strong>';
}
else
{
// show page number 1, no link.
$html[] = '<strong>1</strong>';
}
echo implode('', $html);
Also note that the final ?> is not required in PHP files that do not have HTML code following the PHP code, so I left it off.
Buddy refer this URL
http://www.codediesel.com/php/simple-pagination-in-php/
OR
http://www.phpfreaks.com/tutorial/basic-pagination
Surely will help you.
Thanks
This is a pagination code used for the navigation, any ideas how to get this code to display simply a numbered list of the pages as links?
if (isset($_GET['pageno'])) {
$pageno = $_GET['pageno'];
}
else {
$pageno = 1;
}
if(isset($_GET['niche']))
{
$query = "SELECT count(*) FROM studies WHERE niche = '{$_GET['niche']}'";
$result = mysql_query($query, $connection) or trigger_error("SQL", E_USER_ERROR);
}
$query_data = mysql_fetch_row($result);
$numrows = $query_data[0];
$rows_per_page = 4;
$lastpage = ceil($numrows/$rows_per_page);
$pageno = (int)$pageno;
if ($pageno > $lastpage) {
$pageno = $lastpage;
}
if ($pageno < 1) {
$pageno = 1;
} // if
$limit = 'LIMIT ' .($pageno - 1) * $rows_per_page .',' .$rows_per_page;
$query = "SELECT * FROM studies WHERE niche = '{$_GET['niche']}' $limit";
$result = mysql_query($query, $connection) or trigger_error("SQL", E_USER_ERROR);
and...
if ($pageno == 1) {
echo "<div class='container'>FIRST PREV ";
} else {
echo "<div class='container'> <a href='{$_SERVER['PHP_SELF']}?pageno=1&niche={$_GET['niche']}'>FIRST</a> ";
$prevpage = $pageno-1;
echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$prevpage&niche={$_GET['niche']}'>PREV</a> ";
} // if
echo " ( Page $pageno of $lastpage ) ";
if ($pageno == $lastpage) {
echo " NEXT LAST</div><br />";
} else {
$nextpage = $pageno+1;
echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$nextpage&niche={$_GET['niche']}'>NEXT</a> ";
echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$lastpage&niche={$_GET['niche']}'>LAST</a></div><br /> ";
} // if
?>
Try this:
$totalpages = ceil($numrows / $rows_per_page);
if($totalpages >= 1){ $pagelinkcount = 1; } else { $pagelinkcount = 0; }
while($pagelinkcount <= $totalpages && $totalpages > 1) {
echo "{$pagelinkcount} ";
$pagelinkcount++;
}
On a side note, as Ian Elliot pointed out in the comments for your question, using $_GET in an SQL query leaves your database VERY vulnerable, and is thus considered an extremely insecure coding practice. You should escape and parse the $_GET data that you need diligently before passing it to the DB.
Here's a function I've been using for pagination for a while. It returns nothing if there's only one page, returns up to 15 pages with numbers, then adds a dropdown that lets you skip to any 10th page when there are more than 15 pages. It relies on some prev/next images, but you can easily take that out.
function paginate( $items_per_page, $number_of_results ) {
if( isset( $_REQUEST['page'] ) ) {
$page = $_REQUEST['page'];
} else {
$page = 1;
}
$url = htmlentities( preg_replace( '/(\?|&)page=[\d]+/', '', $_SERVER['REQUEST_URI'] ).'&' );
$html = '';
$numbers_html = '';
$navigation_html = '';
if( $number_of_results > $items_per_page ) {
$html .= '<div class="pagination">';
if( $page == 1 or $page == '1' ) {
$numbers_html .= '<img src="images/prev.png" alt="← prev" class="inactive" /> - ';
} else {
$numbers_html .= '<img src="images/prev.png" alt="← prev" /> - ';
}
$count = 0;
$total_pages = ceil( $number_of_results / $items_per_page )-1;
while( $count <= $total_pages ) {
$count++;
if( $total_pages > 12 and floor($count / 10) != floor($page / 10) ) {
while( $count < $total_pages and floor($count / 10) != floor($page / 10) ) {
if( $count == 1 ) {
$endpage = 9;
} elseif( $count + 9 < $total_pages ) {
$endpage = $count + 9;
} else {
$endpage = $total_pages + 1;
}
$ten_group = floor( $count / 10 );
if( $ten_group == 0 ) {
$navigation_html .= '<option value="'.$url.'page='.$count.'">page 1</option>';
} else {
$navigation_html .= '<option value="'.$url.'page='.$count.'">page '.($ten_group*10).'</option>';
}
$count += 10;
}
$count -= 2;
} else {
if( $page == $count ) {
$numbers_html .= '<span class="current">'.$count.'</span>';
if( $count == 1 ) {
$endpage = 9;
} elseif( $count + 9 < $total_pages ) {
$endpage = $count + 9;
} else {
$endpage = $total_pages + 1;
}
if( $total_pages > 15 ) {
$ten_group = floor( $count / 10 );
if( $ten_group == 0 ) {
$navigation_html .= '<option value="'.$url.'page='.$count.'" selected="selected">page 1</option>';
} else {
$navigation_html .= '<option value="'.$url.'page='.$count.'" selected="selected">page '.($ten_group*10).'</option>';
}
}
} else {
$numbers_html .= ''.$count.'';
}
if( ( $total_pages > 12 and $count % 10 == 9 ) or $count == $total_pages+1 ) {
} else {
$numbers_html .= ' - ';
}
}
}
if( $page != $count ) {
$numbers_html .= ' - <img src="images/next.png" alt="next →" />';
} else {
$numbers_html .= ' - <img src="images/next.png" alt="next →" class="inactive"/>';
}
$count++;
$html .= '<div class="pagination_numbers">'.$numbers_html.'</div>';
if( $navigation_html ) {
$html .= '<div class="pagination_navigation">skip to: <select onchange="window.location=this.value">'.$navigation_html.'</select> of '.($total_pages+1).'</div>';
}
$html .= '</div>';
}
return $html;
}
If you have many pages to display, you might want to consider "logarithmic" page naviagtion, as I describe in my answer here:
How to do page navigation for many, many pages? Logarithmic page navigation
(Sample PHP code only handles the pagination display - not the DB query).