我正试图通过像
这样的链接从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时,显示相关记录,其中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> ";
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
}
}
}
?>
答案 0 :(得分:0)
得到答案我需要在Html开始之前放置代码
<?php
if (isset($_GET["id"]))
{
$_SESSION['page']=$_GET["id"];
$page = $_SESSION['page'];
}
else
{
$page = $_SESSION['page'];
$tableName = $page."r";
}
?>