title: Limit pages numbers on PHP pagination
body: <p>I have a pagination script with PHP. When page records are some hundreds, the pagination result is too big. How I can limit the page numbers/links?</p>
  
  <p>Example: &lt; 1 | 2 ... 37 | 38 | 39 | 40 | 41 | 42 ... 82 | 83 ></p>
  
  <p>This is my PHP script</p>
  
  <pre><code>&lt;?php
  $ppp = 10;
  $rows = mysql_num_rows($query);
  
  $nmpages = ceil($rows/$ppp);
  
  // if current page is not 1, draw PREVIOUS link
  if ($pg &gt; 1 &amp;&amp; $nmpages != 0) {
    echo "&lt;a href=\"?pg=".($pg-1)."\"&gt;&amp;lt;&lt;/a&gt; ";
  }
  
  For($i = 1 ; $i &lt;= $nmpages ; $i++) {
      If($i == $pg) {
        echo "&lt;a href=\"#\" class=\"selected\"&gt;&lt;b&gt;".$i."&lt;/b&gt;&lt;/a&gt; ";
     } else {
        echo "&lt;a href=\"?pg=".$i."\"&gt;".$i."&lt;/a&gt; ";
      }
  }
  // if current page less than max pages, draw NEXT link
  if ($pg &lt; $nmpages &amp;&amp; $nmpages != 0) {
    echo "&lt;a href=\"?pg=".($pg+1)."\"&gt;&amp;gt;&lt;/a&gt;";
  }
  ?&gt;
  </code></pre>
  
  <p>Do you have an ideas how I can do this with the specific PHP script that I have?</p>