的index.php
<script>
$(document).ready(function() {
$("#submit").click(function() {
course = $("#courses").val();
field2 = $("#field2").val();
$("#imagen").show();
$.ajax({
type: "POST",
data: {
"courses": course,
"field2": field2
},
url: "all_college.php",
success: function(data) {
$("#imagen").hide();
$("#popular_colleges").html(data);
}
});
});
});
</script>
<img id="imagen" src="images/please.gif">
<div id="popular_colleges"></div>
all_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 all_colleges where courses like '%,$course,%' LIMIT $start_from, $per_page";
$result = mysqli_query($link,$sql);
while($row = mysqli_fetch_array($result))
{
?>
<?php echo $row['college_name']; ?>
<?php echo $row['address']; ?>
<?php
}
?>
<?php
$query = "select * from all_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>";
?>
在此代码中,当我点击提交按钮时,它将显示最多10个结果,因为我定义$ per_page = 10并且分页编号也显示但是当我点击任意数量的分页时假设我点击2然后索引页面重新加载和数据不会显示。那么,我该如何解决这个问题呢?请帮忙。
谢谢