php - pagination - 10 pages per page -


I have a paging script that displays a list of all pages like:
previous [1 ] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] Next
But I To display ten numbers only at a time:
prev [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] Next

How can I do this? Here's my code:

  & lt ;? Set Php / * current, previous and next page * / $ page = (! Isset ($ _GET ['page'])? 1: $ _GET ['page']; $ Prev = ($ page - 1); $ Next = ($ page + 1); / * maximum result per page * / $ max_results = 2; / * calculate offset / $ = ($ $ * max_results) - $ max_results); / * Query DB for total results You must edit SQL to meet your requirements / $ result = mysql_query ("Choose title from topic"); $ Total_results = mysql_num_rows ($ result); $ Total_pages = roof ($ total_update / $ max_translation); $ Endorsement = ''; / * If a * / if ($ page & gt; 1) {$ Paginagan = '& Lt; A href = "? Page = '. $ Prev.' For 'Loop * /' ($ i = 1; $ i & lt; = $ total_pages; $ i ++) through 'Total & lt; / previous & lt; / a & gt;';} / * ($ Page) == $ i) {$ Paginagan = $ I;} and {$ Paginagan. = '& Lt; A href = "index.php? Page = '. $ I. 'Gt;' $ I. '& Lt; / A & gt; '; }} / * Print the next link if any * / if ($ page & lt; $ total_pages) {$ Paginagan = '& Lt; One hr_ef = "? Page = '. $ Next.'" & Gt; Next & lt; / A & gt; '; } / * Now we have the Pagination Link on our page to print a variable ($ Pagination) to print on the page. I put it in the variable because you want to show * them at the top and bottom of the page * / / * below How do you query DB for results for the current page * / $ result = mysql_query ("Select * LIMIT $ from topics * From, $ max_results "); While ($ i = mysql_fetch_array ($ result)) {echo $ i ['title'] '& Lt; Br / & gt; '; } $ Points on page; ? & Gt;  

10 for next page

  ($ I = $ page + 1; $ i & lt; = min ($ page + 11, $ total_page); $ i ++)  

Or if you want 5 previous and next 5

<$ I < = Min ($ page + 5, $ total_pages); $ I ++) for

Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -