|
PHP中模糊查询后实现分页时,只显示第一页信息,之后的页面信息不显示,求类似问题解决方法最好有代码,谢
<?php
session_start();
header('conten-type:text/html;charset=utf-8');
include('../admin/conn/conn.php');
$OK=false;
$flag=false;
$_SESSION['title']=trim($_POST['title']);
$stmt=$_SESSION['title'];
$k = explode(" ",$stmt);
$pageSize = 15;//每页显示的记录数
if(isset($_GET['currentPage'])){
$currentPage= intval($_GET['currentPage']);
}else{
$currentPage=1;
}
$start = ($currentPage-1)*$pageSize;//每页记录起始值
//获取数据总量
$sql="select count(title_title) as amount from title where title_title like '%$stmt%' ";
$result = $pdo->query($sql);
$row = $result->fetchAll();
$totalRow =$row[0][0];
$totalPage = ceil($totalRow/$pageSize);//总页数
$sql="select title_title,t_name from title inner join teacher inner join t_t where title_title like '%$stmt%' and teacher.t_id=t_t.t_id and t_t.title_id=title.title_id";
$stmt = $pdo->query("$sql limit {$start},$pageSize");
$result = $stmt->fetchAll();
$result1 = $pdo->prepare($sql);
$result1->execute();
$flag=$result1->rowCount();
if($flag==0){
echo '亲,暂时未查询到记录与您的题目匹配,您可以换个关键词试一下^_^';
}
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<table class="table table-bordered table-hover definewidth m10" >
<thead>
<tr>
<th>题目</th>
<th>教师姓名</th>
</tr>
</thead>
<?php foreach ($result as $row){
$row['title_title'] = preg_replace("/($k[0])/i","<font color=#CC0000><b>\\1</b></font>",$row['title_title']);
$row['title_title'] = preg_replace("/($k[0])/i","<font color=#CC0000><b>\\1</b></font>",$row['title_title']);
?>
<tr>
<td><?php echo $title=$row['title_title']; ?></td>
<td><?php echo $title=$row['t_name']; ?></td>
</tr>
<?php } ?>
</table>
<div class="inline pull-right page">
查询匹配记录数:<?php echo $totalRow;?>
页数:<?php echo $currentPage;?>/<?php echo $totalPage;?>
<?php
if ($currentPage == 1){
echo "第一页 上一页 ";
}else {
?>
<a href="?currentPage=1">第一页</a>
<a href="?currentPage=<?php echo $currentPage-1;?>">上一页</a>
<?php }?>
<?php
if ($currentPage == $totalPage){
echo "下一页 尾页 ";
}else {
echo "<a href='?currentPage=$currentPage+1'>下一页</a> ";
echo "<a href='?currentPage=$totalPage'>尾页</a>";
} ?>
</div>
</body>
</html>
|
|