//我需要将分页链接设置为实时搜索输出表。第一个搜索输出页面正确显示(页面上有8行),index.html中的页面计数正确,搜索文本框(search_text)的页面相同。 (图1)
但是在选择第一页的分页链接的数字2 之后,可以看到下一个8行的搜索输出(数字可以看到第1张图片的底部)。它显示错误的输出(与搜索值无关)以及错误的页面“fetch.php”(图片2),即使它应该在 Index.php 上可见,与第一次输出相同。
我需要更正能够转到能够在同一页面显示更多搜索结果的分页链接(搜索结果的数量)的代码(index.html)
//具有正确页数的分页链接
//如果点击分页链接的第2个以查看接下来的8个搜索结果,则显示为贝娄。 (错误的结果和错误的页面 fetch.php ,错误的分页链接)
// index.html用于输入搜索值和搜索结果输出
<thml>
<meta name="viewport" content="width=device-width, initial-scale=1">
<head>
<link rel="stylesheet" type="text/css" href="css/style.css" />
<link rel="stylesheet" type="text/css" href="css/report.css" >
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script src="js/bootstrap.js"></script>
<script>
$(document).ready(function(){
$('#search_text').keyup(function(){
var txt = $(this).val();
if(txt != '')
{
$.ajax({
url:"fetch.php",
method:"post",
data:{search:txt},
dataType:"text",
success:function(data)
{
$('#result').html(data);
}
});
}
else
{
$('#result').html('');
}
});
});
</script>
</head>
<body>
<div class="form-group">
<div class="input-group">
<input type="text" name="search_text" id="search_text" placeholder="Innovation Name" class="form-control" />
</div>
</div>
<br />
<div id="result">
</div>
</body>
// fetch.php文件
<?php
session_start();
include("dbconnection.php");
$output = '';
$sql8="SELECT innid, innname, des, like1 FROM `innovation_tbl` WHERE innname LIKE '%".$_POST["search"]."%' ORDER BY innid DESC";
$result8=mysql_query($sql8);
$count = mysql_num_rows($result8);
$r = mysql_fetch_row($result8);
$numrows = $r[0];
$rowsperpage = 8;
$totalpages = ceil($count / $rowsperpage);
if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) {
$currentpage = (int) $_GET['currentpage'];
} else {
$currentpage = 1;
}
if ($currentpage > $totalpages) {
$currentpage = $totalpages;
}
if ($currentpage < 1) {
$currentpage = 1;
}
$offset = ($currentpage - 1) * $rowsperpage;
$sql9="SELECT innid, innname, des, like1 FROM `innovation_tbl` WHERE innname LIKE '%".$_POST["search"]."%' ORDER BY innid DESC LIMIT $offset, $rowsperpage"; /* do the query again but with limit */
$result9=mysql_query($sql9);
//表的开头
{
echo "<table class='bordered' width='90%' border='0' align='center'>";
echo "<tbody>";
while ($row9=mysql_fetch_array($result9)){
echo "<tr bgcolor='#aadd33'>";
echo "<th><label><strong> ID:</strong></label> <strong>" .$row9['innid']." </strong></th>";
echo "<th><label><strong> </strong></label><strong>" .$row9['innname']. "</strong></th>";
echo "<th> <img src='images/like.png' width='5%' height='16%'>".$row9['like1']."</th>";
echo "</tr>";
echo "<tr>";
echo "<td colspan='3' style='border-bottom-width:100%' bgcolor='#FFFFFF'> <label><strong> Description: </strong></label>" .$row9['des']."<form action='moreinf.php' method='POST'><input name='selectid' id='selectid' type='hidden' value=".$row9['innid']."> <input name='more' type='submit' value='MORE >>' align='right'></form> </td>";
echo "</tr>";
echo "<tr><td colspan='3'> </td> </tr>";
echo "</tbody>";
}
echo "</table>";
}
echo '<table border="0" align="center"><tr><td><strong>';
//构建分页链接
$range = 2;
if ($currentpage > 1) {
$prevpage = $currentpage - 1;
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'>Previous</a> ";
}
for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) {
if (($x > 0) && ($x <= $totalpages)) {
if ($x == $currentpage) {
echo " <font color='#546f3e'><b>$x</b></font> ";
} else {
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> ";
}
}
}
if ($currentpage != $totalpages) {
$nextpage = $currentpage + 1;
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>Next</a> ";
}
//结束构建分页链接
echo '</strong></td></tr></table>';
{
echo 'Innovations Not Found';
}
?>