title: Show only specific range of pages in pagination?
body: <p>I'm doing some paging of mysql results and trying to limit the number of given pages that are listed to a specified variable. It's partially working, but the limit only works at the beginning and end. I believe this is because I need to modify the <code>for</code> loop.</p>
  
  <p>Here is what it currently displays.</p>
  
  <p><img src="https://i.stack.imgur.com/OLkzZ.png" alt="enter image description here"></p>
  
  <p><img src="https://i.stack.imgur.com/EWKmq.png" alt="enter image description here"><br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;^ Should only show 3,4,5,6,7 ^</p>
  
  <p><img src="https://i.stack.imgur.com/bMOVy.png" alt="enter image description here"></p>
  
  <p>PHP:</p>
  
  <pre><code>var $max_pages = 4;
  
  $batch = ceil($this-&gt;page / $this-&gt;links_per_page );
  $end = $batch * $this-&gt;links_per_page;
  if ($end &gt; $this-&gt;total_pages) {
      $end = $this-&gt;total_pages;
  }
  
  $start = 1;
  
  for($i = max($start,$this-&gt;page - $this-&gt;max_pages);
  $i &lt;= min($this-&gt;page + $this-&gt;max_pages,$end); $i ++) {
      if ($i == $this-&gt;page) {
          $prefixActive = '&lt;span class="page_link active"&gt;';
          $links .= $prefixActive . "$i" . $suffix;
      } else {
           $links .= ' ' . '&lt;a href="' . $this-&gt;php_self . 
           '?page=' . $i . $this-&gt;append . '"&gt;' .$prefix . $i .
           $suffix. '&lt;/a&gt;' . ' ';
      }
  }
  </code></pre>