title: Using PHP to search a MySQL database and return paged results
body: <p>I've come across a problem but any help would be appreciated.
  When I query the database using the results posted from a form, the pagination works initially i.e. for the first 10 records but when I click on the 2 hyperlink of the pagination for the second page of results it loses the <code>$_POST</code> variable and returns to the full data set.
  What is the best way of keeping these variables available for the second (and further) pages?</p>
  
  <p>The below is my complete php file.</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;link rel="stylesheet" type="text/css"
  href="design.css"&gt;
  &lt;/head&gt;
  
  
  &lt;body&gt;
  
  &lt;?php
  include("header.php");
  ?&gt;
  &lt;center&gt;
  &lt;div id="content" class="frm"&gt;
  
  &lt;a href='admin.php' style='float:left'&gt;Back!&lt;/a&gt;
  &lt;h2&gt;Search Result&lt;/h2&gt;
  &lt;br&gt;&lt;br&gt;
  &lt;?php
  
  include("../config.inc");
       $find=$_GET['find'];           
             // get page no and set it to page variable, if no page is selected so asign first page bydefualt
               if (isset($_GET["page"])){
                      $page  = $_GET["page"]; 
                  } 
                  else {
                      $page=1;
                  }
                  // count all record in this table then divide it on 10 in order to find the last page----- every page has 10 record display
                      $sql = "SELECT COUNT(*) FROM tt where TTT='$find' "; 
                      $rs_result = mysql_query($sql); 
                      $row = mysql_fetch_row($rs_result); 
                      $total_records = $row[0]; 
                      $total_pages = ceil($total_records / 2);
                      // this line check that page no must be in integer format
                      $page = (int)$page;
                      if ($page &gt; $total_pages) {
                      $page = $total_pages;
                      } // if
                      if ($page &lt; 1) {
                      $page= 1;
                      } // if
  
                      $start_from = ($page-1) * 2;
  
  $q=mysql_query("select * from tt where TTT='$find' order by ID limit $start_from,2");
  $c=mysql_query("select count(*) from tt where TTT='$find'");
  echo "&lt;center&gt;".mysql_result($c,0)."Filtered&lt;/center&gt;";
  echo "&lt;center&gt;";
  echo "&lt;table border='2' bgcolor=#CCCCCC&gt;
  &lt;tr&gt;
  &lt;th&gt;TTT&lt;/th&gt;
  &lt;th&gt;Enroll Date&lt;/th&gt;
  &lt;th&gt;Gradution Date&lt;/th&gt;
  &lt;th&gt;ID&lt;/th&gt;
  &lt;/tr&gt;";
  
  while($row=mysql_fetch_array($q))
  {
  echo "&lt;tr&gt;";
  echo "&lt;td&gt;".$row['TTT']."&lt;/td&gt;";
  echo "&lt;td&gt;".$row['Enroll_Date']."&lt;/td&gt;";
  echo "&lt;td&gt;".$row['Graduation_Date']."&lt;/td&gt;";
  echo "&lt;td&gt;".$row['ID']."&lt;/td&gt;";
  }
  echo "&lt;/table&gt;";
  echo "&lt;center&gt;";
  
                // paginatio start here 
                if ($page== 1) {
                echo " &lt;&lt; &lt; ";
                } else {
               echo " &lt;a href='{$_SERVER['PHP_SELF']}?page=1'&gt;&lt;&lt;&lt;/a&gt; ";
               $prevpage = $page-1;
                 echo " &lt;a href='{$_SERVER['PHP_SELF']}?page=$prevpage'&gt;&lt;&lt;/a&gt; ";
               } // if
               echo " ( Page [$page] of [$total_pages] ) ";
  
               if ($page == $total_pages) {
               echo " &gt; &gt;&gt; ";
               } else {
                $nextpage = $page+1;
                echo " &lt;a href='{$_SERVER['PHP_SELF']}?page=$nextpage'&gt;&gt;&lt;/a&gt; ";
                $lastpage=$total_pages;
                echo " &lt;a href='{$_SERVER['PHP_SELF']}?page=$lastpage'&gt;&gt;&gt;&lt;/a&gt; ";
                } // if
  ?&gt;
  
  &lt;/div&gt;
  &lt;/center&gt;
  
  &lt;?php
  include("footer.php");
  ?&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>