如何在PHP分页传递url变量到下一页


how to pass url variable to next pages in php pagination

我试图通过链接从URL获取值,如

$id =5;

<a href="ifsc-bank.php?id=<?=$id?>">link 1</a>

和我有一个列表的链接大约50像

link 1 
link 2
link 3
.
.
link 50

当点击链接时,它将路由到ifsc-bank.php并在ifsc-bank.php中使用$_GET获取值

$id=$_GET['id'];
$query = "SELECT * FROM distdb WHERE BANK_ID = '$id'";
产出

    1 record 
    2 record2
    3 record3
`First 1 2 3 Next` is my pagination 

当我点击1,它的fine显示相关的记录,其中id = $id但是点击2,它没有显示任何记录。

我不明白为什么过滤器在其他页面不起作用

听到的是我的代码

<?php 
 include('dbconfig.inc.php');
        $id=$_GET['id'];
        $query = "SELECT * FROM distdb WHERE BANK_ID = '$id'";       
        $records_per_page=10;
        $newquery = $paginate->paging($query,$records_per_page);
        $paginate->dataview($newquery);
        $paginate->paginglink($query,$records_per_page);
        ?>

分页

<?php
class paginate
{
    private $db;
    function __construct($dbh)
    {
        $this->db = $dbh;
    }
    public function dataview($query)
    {
        $stmt = $this->db->prepare($query);
        $stmt->execute();
        if($stmt->rowCount()>0)
        {
            while($row=$stmt->fetch(PDO::FETCH_ASSOC))
            {
    $bank = $row['BANK'];
    $ifsc = $row['IFSC'];
    $branch= $row['BRANCH'];
    $micr = $row['MICR_CODE'];
    $address = $row['ADDRESS'];
    $contact = $row['CONTACT'];
    $city = $row['CITY'];
    $district = $row['DISTRICT'];
    $state = $row['STATE'];
    $bankcode=$row['IFSC'];
    $brcode = substr($bankcode, -6);
                ?>
     <table align="center" width="100%" class="t_data">
     <tbody>   
      <tr>
       <td width="21%"><?=$bank?></td> 
       <td width="20%"><?=$branch?></td>
       <td width="20%"><b>IFSC:</b><?=$ifsc?> <br /><b>MICR:</b><?=$micr?><br /><b>Branch Code:</b><?=$brcode?></td>
       <td width="24%"><?=$address?><br /> <b>City :</b><?=$city?> <br /> <b>District :</b><?=$district?> <br /> <b>State:</b> <?=$state?></td> 
       <td width="15%"><?=$contact?></td>
      </tr>
     </tbody>
     </table> 

     <?php
            }
        }
        else
        {
            ?>
            <tr>
            <td>Nothing here...</td>
            </tr>
     <?php
        }
    }
    public function paging($query,$records_per_page)
    {
        $starting_position=0;
        if(isset($_GET["page_no"]))
        {
            $starting_position=($_GET["page_no"]-1)*$records_per_page;
        }
        $query2=$query." limit $starting_position,$records_per_page";
        return $query2;
    }
    public function paginglink($query,$records_per_page)
    {
        $self = $_SERVER['PHP_SELF'];
        $stmt = $this->db->prepare($query);
        $stmt->execute();
        $total_no_of_records = $stmt->rowCount();
        if($total_no_of_records > 0)
        {
            ?>
           <br  /> 
           <table width="100%"   align="left"  >
           <tr>
           <td height="54">
            <?php
            $total_no_of_pages=ceil($total_no_of_records/$records_per_page);
            $current_page=1;
            if(isset($_GET["page_no"]))
            {
                $current_page=$_GET["page_no"];
            }
            if($current_page!=1)
            {
                $previous =$current_page-1;
                echo "<a href='".$self."?page_no=1'>First</a>&nbsp;&nbsp;";
                echo "<a href='".$self."?page_no=".$previous."'>Previous</a>&nbsp;&nbsp;";
            }
            $x="";
for($i=1;$i<=$total_no_of_pages;$i++) {
  if($i==$current_page) {
     $x.= "<strong><a href='".$self."?page_no=".$i."' style='color:red;text-decoration:none'>".$i."</a></strong>&nbsp;&nbsp;";
  } 
  elseif ($i>5 && $i!=$total_no_of_pages) {
     $x.= " ";
  }
  else {
     $x.= "<a href='".$self."?page_no=".$i."'>".$i."</a>&nbsp;&nbsp;";
  }
}
echo $x;
            if($current_page!=$total_no_of_pages)
            {
                $next=$current_page+1;
                echo "<a href='".$self."?page_no=".$next."'>Next</a>&nbsp;&nbsp;";
                echo "<a href='".$self."?page_no=".$total_no_of_pages."'>Last</a>&nbsp;&nbsp;";
            }
            ?>
       </td></tr> 
             </table> 
            <?php
        }
    }
}
 ?>

得到答案我需要将代码放在Html开始前

<?php
if (isset($_GET["id"]))
    {   
        $_SESSION['page']=$_GET["id"];
        $page = $_SESSION['page'];
    }
else
{
    $page = $_SESSION['page'];
    $tableName = $page."r"; 
}
?>