的index.php:
<script>
$(document).ready(function(){
$("#submit2").click(function(){
course = $("#courses").val();
field2 = $("#field2").val();
$("#imagen").show();
$.ajax({
type:"POST",
data:{"courses":course,"field2":field2},
url:"college.php",
success:function(data){
$("#imagen").hide();
$("#popular_colleges").html(data);
}
});
});
});
</script>
<img id="imagen" src="please.gif">
<div id ="popular_colleges"></div>
college.php
<?php
$course = $_POST['courses'];
$field2 = $_POST['field2'];
$per_page=10;
if (isset($_GET["page"]))
{
$page = $_GET["page"];
}
else {
$page=1;
}
$start_from = ($page-1) * $per_page;
$sql = "select * from college where course like '%,$course,%' LIMIT $start_from, $per_page";
$result = mysqli_query($link,$sql);
while($row = mysqli_fetch_array($result))
{
echo $row['logo'];
echo $row['collegename'];
echo $row['stream'];
}
?>
<?php
$query = "select * from colleges";
$result = mysqli_query($link, $query);
$total_records = mysqli_num_rows($result);
$total_pages = ceil($total_records / $per_page);
echo "<center><a href='index.php?page=1' style='padding:10px;'>".'First Page'."</a>";
$skipped = false;
for ($i = 1; $i <= $total_pages; $i++) {
if ($i < 3 || $total_pages- $i < 3 || abs($page - $i) < 3) {
if ($skipped)
echo '<span> ... </span>';
$skipped = false;
echo "<a href='index.php?page=" . $i . "' style='padding:5px;'>" . $i . "</a>";
} else {
$skipped = true;
}
}
echo "<a href='index.php?page=$total_pages' style='padding:10px;'>".'Last Page'."</a></center>";
?>
在此代码中,当我点击submit2按钮时,它显示分页,但是当我点击任何分页编号时,它将重新加载相同的页面,但我希望在点击分页编号时不要加载页面并显示结果同一页。
答案 0 :(得分:0)
index.php?page=
,但你没有在index.php中对页面变量做任何事情。正如我可以看到您在college.php
中使用它,但college.php
没有收到页面变量。
您正在发送POST请求并尝试从$ _GET获取页面。 You can only have one verb (POST, GET, PUT, ...) when doing an HTTP Request.
您正在通过AJAX向college.php
发送数据。
data:{"courses":course,"field2":field2}
如您所见,您没有发送页面。你也需要发送页面。
data:{"courses":course,"field2":field2, "page": page}
并使用$_POST['page']
代替$_GET['page']