我正在尝试使用PHP + MySQL + JQuery在我的JQuery表中创建一个分页,但我不知道如何实现它。
这就是为什么我需要你的帮助,我需要一个简单的分页(我不介意它是否真的很简单)我只是需要它才能工作,因为它是我第一个JQuery表中的最后一步。
我将发布我的网站的网址与表格工作(目前没有分页,我有超过500个条目,但我只在开头显示20个。)
网址:Click Here
脚本JQuery:
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
function makeTable(data) {
var tbl_body = "";
$.each(data, function () {
var tbl_row = "";
$.each(this, function (k, v) {
tbl_row += "<td>" + v + "</td>";
})
tbl_body += "<tr>" + tbl_row + "</tr>";
})
return tbl_body;
}
function getEmployeeFilterOptions() {
var opts = [];
$checkboxes.each(function () {
if (this.checked) {
opts.push(this.name);
}
});
return opts;
}
function updateEmployees(opts) {
$.ajax({
type: "POST",
url: "submit.php",
dataType: 'json',
cache: false,
data: {
filterOpts: opts
},
success: function (records) {
$('#employees tbody').html(makeTable(records));
// here, after the content is inside DOM/visible we activate the plugin
}
});
}
var $checkboxes = $("input:checkbox");
$checkboxes.on("change", function () {
var opts = getEmployeeFilterOptions();
updateEmployees(opts);
});
$(document).ajaxStart(function () {
$('#loading').fadeIn("slow");
}).ajaxStop(function () {
$('#loading').fadeOut("slow");
});
$(window).load(function () {
updateEmployees();
});
</script> `
这里也是PHP的SQL部分:
$sql = $select . $from . $where;
$statement = $pdo->prepare($sql);
$statement->execute();
$results = $statement->fetchAll(PDO::FETCH_ASSOC);
$json = json_encode($results);
echo($json);
答案 0 :(得分:-1)
您需要在表格底部添加分页按钮,单击它们时,您可以使用按钮上的页码作为参数调用php发送者脚本。 然后从PHP脚本中,您需要在最后的mySQL查询中添加LIMIT语句。 添加
LIMIT A,B
A是您的页码*页面上的文章数量。 B是您的页码*页面上的文章数量+页面上的文章数量。
当你收到数据时,在添加新行之前清除你的表。
$("#employees tbody").remove();