gpt4 book ai didi

php - 筛选结果的分页

转载 作者:行者123 更新时间:2023-11-29 17:46:00 25 4
gpt4 key购买 nike

我正在尝试采用 Sebastian Sulinski 设计的高级搜索表单,可在 https://github.com/ssd-tutorials/advanced-search-form/tree/master/new_improved_version_completed 上找到。

我尝试集成示例分页类,但它不起作用。

对结果应用分页有什么想法吗?

最佳答案

HardcoreHenry,我将 getrecords 函数更改为:

function getRecords($search = null) {

$items = array();
$params = array();

$connect = mysqli_connect("localhost", "root", "", "acsdb");
$record_per_page = 50;
$page = '';
$output = '';
if(isset($_POST["page"]))
{
$page = $_POST["page"];
}
else
{
$page = 1;
}
$start_from = ($page - 1)*$record_per_page;
$sql = "SELECT DISTINCT(`staff`.`staffname`), `staff`.`indexno` AS `index`,
locations.name, staff.email FROM `staff` JOIN `locations` ON `locations`.`id` = `staff`.`slocationid` ";

if (!empty($search) && is_array($search)) {

foreach($search as $key => $value) {

switch($key) {

case 'keyword':
$items[] = "`staff`.`staffname` LIKE ?";
$params[] = "%{$value}%";
break;

case 'locations':
$items[] = "`locations`.`id` = ?";
$params[] = $value;
break;


case 'locationm':
$items[] = "`staff`.`slocationid` IN (
SELECT `id`
FROM `locations`
WHERE `id` = ?
)";
$params[] = $value;
break;







}

}

if (!empty($items)) {

$sql .= " WHERE ";
$sql .= implode(" AND ", $items);

}

}

$sql .= " ORDER BY `staff`.`staffname` ASC LIMIT $start_from, $record_per_page";

return fetchRecords($sql, $params);


}

并添加

 <script>  
$(document).ready(function(){
load_data();
function load_data(page)
{
$.ajax({
url:"functions.php",
method:"POST",
data:{page:page},
success:function(data){
$('#pagination_data').html(data);
}
})
}
$(document).on('click', '.pagination_link', function(){
var page = $(this).attr("id");
load_data(page);
});
});
</script>

到index.php

关于php - 筛选结果的分页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49821870/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com