title: PHP pagination loses variable on other pages
body: <p>I have a value that is passed to my search results page via $_POST and stored in a variable called $term.  The variable is then in a MySQL query which then runs to display the search results and if there are more than 15 results I have a pagination php script which breaks the results up into several pages.</p>
  
  <p>The first page is great, the correct number of results are found and the correct number of pages are available.  If I echo the variable the correct value is stored in it.  However, if I  chose to look at the next lot of results and the page refreshes all the rows of the table are listed (as if the query was just SELECT * with no argument) and the variable is now empty</p>
  
  <p>Here is my code (it's a bit long, sorry, I intend to put a big chuck of it away in another page and include it once it's working correctly)</p>
  
  <pre><code>    &lt;?php
  $tbl_name="accounts";
  $adjacents = 3;
  
  
  if (isset($_POST['basic_search_submit'])){
  $term = $_POST['item'];}
  
  $query = "SELECT COUNT(*) as num FROM accounts LEFT JOIN accounts_cstm ON accounts.id = accounts_cstm.id_c  WHERE accounts.name LIKE '%$term%' ORDER BY accounts.name";
  $total_pages = mysql_fetch_array(mysql_query($query));
  $total_pages = $total_pages[num];
  
      $targetpage = "search_results_play.php";    
  $limit = 15;                                
  $page = $_GET['page'];
  if($page) 
      $start = ($page - 1) * $limit;          
  else
      $start = 0;                             
      $sql = "SELECT * FROM accounts LEFT JOIN accounts_cstm ON accounts.id = accounts_cstm.id_c WHERE accounts.name LIKE '%$term%' ORDER BY accounts.name LIMIT $start, $limit";
  $result = mysql_query($sql);
  if ($page == 0) $page = 1;                  
  $prev = $page - 1;                          
  $next = $page + 1;                          
  $lastpage = ceil($total_pages/$limit);      
  $lpm1 = $lastpage - 1;                      
  $pagination = "";
  
  if($lastpage &gt; 1)
  {   
      $pagination .= "&lt;div class=\"pagination\"&gt;";
              if ($page &gt; 1) 
          $pagination.= "&lt;a href=\"$targetpage?page=$prev\"&gt;&amp;#60; &amp;#60; previous&lt;/a&gt;";
      else
          $pagination.= "&lt;span class=\"disabled\"&gt;&amp;#60; &amp;#60; previous&lt;/span&gt;";   
  
              if ($lastpage &lt; 7 + ($adjacents * 2))
      {   
          for ($counter = 1; $counter &lt;= $lastpage; $counter++)
          {
              if ($counter == $page)
                  $pagination.= "&lt;span class=\"current\"&gt;$counter&lt;/span&gt;";
              else
                  $pagination.= "&lt;a href=\"$targetpage?page=$counter\"&gt;$counter&lt;/a&gt;";                 
          }
      }
      elseif($lastpage &gt; 5 + ($adjacents * 2))    //enough pages to hide some
      {
                      if($page &lt; 1 + ($adjacents * 2))        
          {
              for ($counter = 1; $counter &lt; 4 + ($adjacents * 2); $counter++)
              {
                  if ($counter == $page)
                      $pagination.= "&lt;span class=\"current\"&gt;$counter&lt;/span&gt;";
                  else
                      $pagination.= "&lt;a href=\"$targetpage?page=$counter\"&gt;$counter&lt;/a&gt;";                 
              }
              $pagination.= "...";
              $pagination.= "&lt;a href=\"$targetpage?page=$lpm1\"&gt;$lpm1&lt;/a&gt;";
              $pagination.= "&lt;a href=\"$targetpage?page=$lastpage\"&gt;$lastpage&lt;/a&gt;";       
          }
                      elseif($lastpage - ($adjacents * 2) &gt; $page &amp;&amp; $page &gt; ($adjacents * 2))
          {
              $pagination.= "&lt;a href=\"$targetpage?page=1\"&gt;1&lt;/a&gt;";
              $pagination.= "&lt;a href=\"$targetpage?page=2\"&gt;2&lt;/a&gt;";
              $pagination.= "...";
              for ($counter = $page - $adjacents; $counter &lt;= $page + $adjacents; $counter++)
              {
                  if ($counter == $page)
                      $pagination.= "&lt;span class=\"current\"&gt;$counter&lt;/span&gt;";
                  else
                      $pagination.= "&lt;a href=\"$targetpage?page=$counter\"&gt;$counter&lt;/a&gt;";                 
              }
              $pagination.= "...";
              $pagination.= "&lt;a href=\"$targetpage?page=$lpm1\"&gt;$lpm1&lt;/a&gt;";
              $pagination.= "&lt;a href=\"$targetpage?page=$lastpage\"&gt;$lastpage&lt;/a&gt;";       
          }
  
          else
          {
              $pagination.= "&lt;a href=\"$targetpage?page=1\"&gt;1&lt;/a&gt;";
              $pagination.= "&lt;a href=\"$targetpage?page=2\"&gt;2&lt;/a&gt;";
              $pagination.= "...";
              for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter &lt;= $lastpage; $counter++)
              {
                  if ($counter == $page)
                      $pagination.= "&lt;span class=\"current\"&gt;$counter&lt;/span&gt;";
                  else
                      $pagination.= "&lt;a href=\"$targetpage?page=$counter\"&gt;$counter&lt;/a&gt;";                 
              }
          }
      }
  
  
      if ($page &lt; $counter - 1) 
          $pagination.= "&lt;a href=\"$targetpage?page=$next\"&gt;next &amp;#62; &amp;#62;&lt;/a&gt;";
      else
          $pagination.= "&lt;span class=\"disabled\"&gt;next &amp;#62; &amp;#62;&lt;/span&gt;";
      $pagination.= "&lt;/div&gt;\n";       
  }
  ?&gt;
  
    &lt;? while ($row = mysql_fetch_array($result)){
   //table displaying results
   }
  ?&gt;
  &lt;?=$pagination?&gt;
  </code></pre>
  
  <p>Any help would be greatly appreciated, thanks</p>