title: hide some pages from php pagination system with sql
body: <p>As the title says, I want to hide some pages from my pagination system. Because the table that it selects from is huge so it creates thousands of numbers.</p>
  
  <p>So i want it to be something like
  First Page 1 2 3 4 ... Last Page</p>
  
  <p>And if i click on page for it should show this
  First Page 1 2 3 4 5 6 7 8 ... Last page</p>
  
  <p>And if i click on page 8 it should show this
  First page ... 4 5 6 7 8 9 10 11 ... Last Page</p>
  
  <p>So here is my php pagination script</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
    &lt;head&gt;
      &lt;title&gt;PHP Pagination&lt;/title&gt;
    &lt;/head&gt;
  &lt;body&gt;
      &lt;table align="center" border="2" cellpadding="3"&gt;
          &lt;tr&gt;
              &lt;th&gt;Name&lt;/th&gt;
              &lt;th&gt;quality&lt;/th&gt;
              &lt;th&gt;RequiredLevel&lt;/th&gt;
          &lt;/tr&gt;
          &lt;?php
              $con = mysqli_connect('127.0.0.1', 'root', 'ascent', 'world');
  
              $per_page=500;
  
              if (isset($_GET["page"])) {
                  $page = $_GET["page"];
              }else{
                  $page=1;
              }
  
              $start_from = ($page-1) * $per_page;
  
              $stmt = $con-&gt;prepare("SELECT name, Quality, RequiredLevel  FROM item_template LIMIT $start_from, $per_page");
  
              $stmt-&gt;execute();
  
              $stmt-&gt;bind_result($name, $quality, $reqlvl);
  
              $stmt-&gt;store_result();
  
              while($stmt-&gt;fetch()) {
  
                  if($stmt-&gt;num_rows &gt; 0) {
                      echo "&lt;tr align='center'&gt;";
                      echo "&lt;td&gt;$name&lt;/td&gt;";
                      echo "&lt;td&gt;$quality&lt;/td&gt;";
                      echo "&lt;td&gt;$reqlvl&lt;/td&gt;";
                      echo "&lt;/tr&gt;";
                  }
              }
          ?&gt;
      &lt;/table&gt;
      &lt;div&gt;
          &lt;?php
              $stmt = $con-&gt;prepare("SELECT * FROM item_template");
  
              $stmt-&gt;execute();
  
  
              $stmt-&gt;store_result();
  
              if($stmt-&gt;num_rows &gt; 0) {
                  $total_records = $stmt-&gt;num_rows;
                  $total_pages = ceil($total_records / $per_page);
  
                  echo "&lt;center&gt;&lt;a href='index.php?page=1'&gt;First Page&lt;/a&gt;";
  
                  for ($i=1; $i&lt;=$total_pages; $i++) {
                      if($page &lt; 4)
                      echo "&lt;a href='index.php?page=$i'&gt;$i&lt;/a&gt; ";
                  }
  
                  echo "&lt;a href='index.php?page=$total_pages'&gt;Last Page&lt;/a&gt;&lt;/center&gt; ";       
              }
          ?&gt;
      &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>