mysql - Php Pagination while passing Query String -


in php,while passing query string page page how pagination.the following code used works fine pagination without query string while passing value page page(query string) dint work. please give me suggestions.

<?php include("connect.php"); $adjacents = 3; $id = $_request["id"]; $query = "select count(*) num 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 data 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 > 1) {        $pagination .= "<div class=\"pagination\">";      if ($page > 1)          $pagination.= "<a href=\"$targetpage?id=$id?page=$prev\">previous</a>";     else         $pagination.= "<span class=\"disabled\">previous</span>";         if ($lastpage < 7 + ($adjacents * 2))        {            ($counter = 1; $counter <= $lastpage; $counter++)         {             if ($counter == $page)                 $pagination.= "<span class=\"current\">$counter</span>";             else                 $pagination.= "<a href=\"$targetpage?id=$id?page=$counter\">$counter</a>";                           }     }     elseif($lastpage > 5 + ($adjacents * 2))         {         if($page < 1 + ($adjacents * 2))                 {             ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++)             {                 if ($counter == $page)                     $pagination.= "<span class=\"current\">$counter</span>";                 else                     $pagination.= "<a href=\"$targetpage?id=$id?page=$counter\">$counter</a>";                               }             $pagination.= "...";             $pagination.= "<a href=\"$targetpage?id=$id?page=$lpm1\">$lpm1</a>";             $pagination.= "<a href=\"$targetpage?id=$id?page=$lastpage\">$lastpage</a>";                 }         elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2))         {             $pagination.= "<a href=\"$targetpage?id=$id?page=1\">1</a>";             $pagination.= "<a href=\"$targetpage?id=$id?page=2\">2</a>";             $pagination.= "...";             ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++)             {                 if ($counter == $page)                     $pagination.= "<span class=\"current\">$counter</span>";                 else                     $pagination.= "<a href=\"$targetpage?id=$id?page=$counter\">$counter</a>";                               }             $pagination.= "...";             $pagination.= "<a href=\"$targetpage?id=$id?page=$lpm1\">$lpm1</a>";             $pagination.= "<a href=\"$targetpage?id=$id?page=$lastpage\">$lastpage</a>";                 }         else         {             $pagination.= "<a href=\"$targetpage?id=$id?page=1\">1</a>";             $pagination.= "<a href=\"$targetpage?id=$id?page=2\">2</a>";             $pagination.= "...";             ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++)             {                 if ($counter == $page)                     $pagination.= "<span class=\"current\">$counter</span>";                 else                     $pagination.= "<a href=\"$targetpage?id=$id?page=$counter\">$counter</a>";                               }         }     }      //next button     if ($page < $counter - 1)          $pagination.= "<a href=\"$targetpage?id=$id?page=$next\">next</a>";     else         $pagination.= "<span class=\"disabled\">next</span>";     $pagination.= "</div>\n";     }     ?> <tr> <td><?php echo $rs['name']; ?></td> <td><?php echo $rs['email']; ?></td> <td><?php echo $rs['dateins']; ?></td> </tr> <?php           }           ?>  <td><input type="hidden" name="id" id="id" value="<?php echo $id; ?>"></td>  </table>  <?php echo $pagination; ?>  ?> 

thanks in advance.

you need add $_get variables want see links in pagination otherwise after first request not able use them.

for example:

  if ($page > 1)          $pagination.= "<a href=\"$targetpage?id=$id&page=$prev&something=$_get['something']\">previous</a>";     else         $pagination.= "<span class=\"disabled\">previous</span>"; 

i noticed $_get variables set wrong in links.

this

<a href=\"$targetpage?id=$id?page=$lastpage\">$lastpage</a> 

should

<a href=\"$targetpage?id=$id&page=$lastpage\">$lastpage</a> 

it might easier add other variables session dont need worry dymanically adding them query string if there more one.


Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -