【发布时间】:2015-07-26 15:48:34
【问题描述】:
我正在尝试通过链接从 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
}
}
}
?>
【问题讨论】:
-
你能包含你的 PHP 吗?您也可以使用此代码进行 SQL 注入。
-
我的代码被添加并告诉我如何避免这种情况???
-
将用户输入与 SQL 分开。 stackoverflow.com/questions/60174/…
-
好的,我会这样做,但你检查代码是否有问题
-
点击链接2时页面的来源是什么?
标签: php jquery pagination