title: Php Pagination while passing Query String
body: <p>In Php,while passing query string from page to another page how to do pagination.The following code I used it works fine for pagination without query string but while passing value from page to another page(Query String) it dint work.
  Please give me any suggestions.</p>
  
  <pre><code>&lt;?php
  include("connect.php");
  $adjacents = 3;
  $id = $_REQUEST["id"];
  $query = "SELECT COUNT(*) as num FROM data";
  $total_pages = mysql_fetch_array(mysql_query($query));
  $total_pages = $total_pages[num];
  
  $targetpage = "pagetest.php";
  $limit = 10;
  $page = $_GET['page'];
  if($page)
      $start = ($page - 1) * $limit;
  else
      $start = 0;
  
  $sql = "SELECT name,email,dateins FROM data WHERE name='$id' LIMIT $start, $limit";
  $result = mysql_query($sql);
  
  $cnt=0;
  
                    if($result)
                    while($rs=mysql_fetch_assoc($result))
                    {
                    $cnt=$cnt+1;
                    $cssRow="class='gridRow'";
                    if(($cnt%2)==1)
                    {
                       $cssRow="class='gridRowAlternate'";
                    }
  
  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?id=$id?page=$prev\"&gt;Previous&lt;/a&gt;";
      else
          $pagination.= "&lt;span class=\"disabled\"&gt;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?id=$id?page=$counter\"&gt;$counter&lt;/a&gt;";                  
          }
      }
      elseif($lastpage &gt; 5 + ($adjacents * 2))    
      {
          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?id=$id?page=$counter\"&gt;$counter&lt;/a&gt;";                  
              }
              $pagination.= "...";
              $pagination.= "&lt;a href=\"$targetpage?id=$id?page=$lpm1\"&gt;$lpm1&lt;/a&gt;";
              $pagination.= "&lt;a href=\"$targetpage?id=$id?page=$lastpage\"&gt;$lastpage&lt;/a&gt;";        
          }
          elseif($lastpage - ($adjacents * 2) &gt; $page &amp;&amp; $page &gt; ($adjacents * 2))
          {
              $pagination.= "&lt;a href=\"$targetpage?id=$id?page=1\"&gt;1&lt;/a&gt;";
              $pagination.= "&lt;a href=\"$targetpage?id=$id?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?id=$id?page=$counter\"&gt;$counter&lt;/a&gt;";                  
              }
              $pagination.= "...";
              $pagination.= "&lt;a href=\"$targetpage?id=$id?page=$lpm1\"&gt;$lpm1&lt;/a&gt;";
              $pagination.= "&lt;a href=\"$targetpage?id=$id?page=$lastpage\"&gt;$lastpage&lt;/a&gt;";        
          }
          else
          {
              $pagination.= "&lt;a href=\"$targetpage?id=$id?page=1\"&gt;1&lt;/a&gt;";
              $pagination.= "&lt;a href=\"$targetpage?id=$id?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?id=$id?page=$counter\"&gt;$counter&lt;/a&gt;";                  
              }
          }
      }
  
      //next button
      if ($page &lt; $counter - 1) 
          $pagination.= "&lt;a href=\"$targetpage?id=$id?page=$next\"&gt;Next&lt;/a&gt;";
      else
          $pagination.= "&lt;span class=\"disabled\"&gt;Next&lt;/span&gt;";
      $pagination.= "&lt;/div&gt;\n";
      }
      ?&gt;
  &lt;tr&gt;
  &lt;td&gt;&lt;?php echo $rs['name']; ?&gt;&lt;/td&gt;
  &lt;td&gt;&lt;?php echo $rs['email']; ?&gt;&lt;/td&gt;
  &lt;td&gt;&lt;?php echo $rs['dateins']; ?&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;?php
            }
            ?&gt;
   &lt;td&gt;&lt;input type="hidden" name="id" id="id" value="&lt;?php echo $id; ?&gt;"&gt;&lt;/td&gt;
   &lt;/table&gt;
   &lt;?php echo $pagination; ?&gt;
   ?&gt;
  </code></pre>
  
  <p>THANKS IN ADVANCE.</p>