Я пытаюсь получить значение из 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 и получить значение с помощью $ _GET в ifsc-bank.php
$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, то это показывает его связанные записи, где 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 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> "; echo "<a href='".$self."?page_no=".$previous."'>Previous</a> "; } $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> "; } elseif ($i>5 && $i!=$total_no_of_pages) { $x.= " "; } else { $x.= "<a href='".$self."?page_no=".$i."'>".$i."</a> "; } } echo $x; if($current_page!=$total_no_of_pages) { $next=$current_page+1; echo "<a href='".$self."?page_no=".$next."'>Next</a> "; echo "<a href='".$self."?page_no=".$total_no_of_pages."'>Last</a> "; } ?> </td></tr> </table> <?php } } } ?>
в<?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> "; echo "<a href='".$self."?page_no=".$previous."'>Previous</a> "; } $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> "; } elseif ($i>5 && $i!=$total_no_of_pages) { $x.= " "; } else { $x.= "<a href='".$self."?page_no=".$i."'>".$i."</a> "; } } echo $x; if($current_page!=$total_no_of_pages) { $next=$current_page+1; echo "<a href='".$self."?page_no=".$next."'>Next</a> "; echo "<a href='".$self."?page_no=".$total_no_of_pages."'>Last</a> "; } ?> </td></tr> </table> <?php } } } ?>
получил ответ, мне нужно поместить код до начала Html
<?php if (isset($_GET["id"])) { $_SESSION['page']=$_GET["id"]; $page = $_SESSION['page']; } else { $page = $_SESSION['page']; $tableName = $page."r"; } ?>