title: How to limit pages in pagination in php
body: <p>i want to make the pages not go beyond 10
  this the code that shows the number of pages</p>
  
  <pre><code>for ($page=1;$page&lt;=$number_of_pages;$page++) {
   echo '&lt;a href="m.search.php?page=' . $page . '"&gt;' . $page . '&lt;/a&gt; ';
  }`
  </code></pre>
  
  <p>this is the output:</p>
  
  <p>1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25</p>
  
  <p>and i want to make it go like this</p>
  
  <p>1 2 3 4 5 6 7 8 9 10 ...</p>
  
  <p>and if im on page 10 it will show like this</p>
  
  <p>1 .. 10 11 12 13 14 15 16 17 18 19 20 ... 25</p>
  
  <p>i don't have any idea how to make this work</p>
  
  <p>this is the source</p>
  
  <pre><code>&lt;?php
  if(isset($_POST['search']))
  {
  unset($_SESSION['keyword']);
  $KeyWord = $_POST['keyword'];
  $_SESSION['keyword'] = $KeyWord;
  }
  $KW = $_SESSION['keyword'];
  $results_per_page = 1;
  $sql="SELECT * FROM books_data WHERE Book_Title LIKE '%$KW%' OR Book_Author         
  LIKE '%$KW%' ORDER BY Book_Title";
  $result = mysqli_query($connect, $sql);
  $number_of_results = mysqli_num_rows($result);
  
  $number_of_pages = ceil($number_of_results/$results_per_page);
  
  if (!isset($_GET['page'])) {
    $page = 1;
  } else {
    $page = $_GET['page'];
  }
  
  $this_page_first_result = ($page-1)*$results_per_page;
  $sql="SELECT * FROM books_data WHERE Book_Title LIKE '%$KW%' OR Book_Author LIKE '%$KW%' ORDER BY Book_Title LIMIT $this_page_first_result,         $results_per_page";
  $result = mysqli_query($connect, $sql);
  $query = "SELECT * FROM books_data WHERE Book_Title LIKE '%$KW%' OR  Book_Author LIKE '%$KW%' ORDER BY Book_Title ASC";
  $sql = mysqli_query($connect, $query);
  $nurows = mysqli_num_rows($sql);
  $numrows = $connect-&gt;query($query);
  if($nurows == 0 OR $nurows == 1)
  {
  $restext = "result";
  }
  else
  {
  $restext = "results";
  }
  if(isset($_POST['search']))
  {
  $num = 0;
  $desc = "result. Keyword is blank... Please try again.";
  }
  else
  {
  $num = '';
  $desc = '';
  }
  ?&gt;
  &lt;p&gt;&lt;strong&gt;&lt;?php $num ?&gt; &lt;/strong&gt;&lt;?php $desc ?&gt; &lt;/p&gt;
  &lt;?php 
  ?&gt; &lt;p&gt;&lt;strong&gt;&lt;?php echo $nurows; ?&gt; &lt;/strong&gt; &lt;?php echo $restext;?&gt; for '&lt;?php echo $KW; ?&gt;'&lt;/p&gt;
  &lt;?php
  while($row = mysqli_fetch_array($result)) {
  
  $bookid = $row['Book_ID'];
  $booktitle = $row['Book_Title'];
  $bookauthor = $row['Book_Author'];
  $bookimg = $row['Book_IMG_Name'];
  
  echo "&lt;hr&gt;&lt;a href=\"../../pass.php?id=$bookid&amp;kw=$KW\"&gt;&lt;img src='../../images/bookimg/$bookimg' class='bookimg'&gt;&lt;/a&gt;&lt;h3&gt;&lt;a href=\"../../pass.php?id=$bookid&amp;kw=$KW\"&gt;$booktitle&lt;/a&gt;&lt;/hr&gt;&lt;p&gt;&lt;font style='font-size: 15px;'&gt;&lt;font style='font-style: italic;'&gt;by " . $bookauthor . '&lt;/p&gt;&lt;/font&gt;&lt;br /&gt;';
  
  }
  
  for ($page=1;$page&lt;=$number_of_pages;$page++) {
    echo '&lt;a href="m.search.php?page=' . $page . '"&gt;' . $page . '&lt;/a&gt; ';
  }
  </code></pre>