我正在使用 PHP 进行分页,并且有下一页和上一页提交按钮,因此如果用户在第 1 页检查 2 个值,我将其存储在会话变量中,当他返回时,我使用in_array
并回显该值。但是如果用户取消选中,我如何取消设置数组中的值?如果用户未选中该复选框,则无法取消设置会话数组中的值。
我想我的解释很清楚,但如果有些人需要代码而不是这里
if(!empty($_POST['rec_num'])) {
if(empty($_SESSION['checks_selected_for_records'])) {
//If session array is empty than directly add all record numbers in
//this session
$_SESSION['checks_selected_for_records'] = $_POST['rec_num'];
}
//If a new value is seen and is not in array than add it
foreach ($_POST['rec_num'] as $check_rec_num) {
if(!in_array($check_rec_num, $_SESSION['checks_selected_for_records'])) {
array_push($_SESSION['checks_selected_for_records'], $check_rec_num);
}
}
}
//Handle Redirects For Pagination
if (isset($_POST['next_page']) || isset($_POST['last_page']) || isset($_POST['first_page']) || isset($_POST['previous_page'])) {
if(isset($_POST['next_page_link'])) {
redirect_to($_POST['next_page_link']);
} elseif (isset($_POST['last_page'])) {
redirect_to($_POST['last_page_link']);
} elseif (isset($_POST['first_page'])) {
redirect_to($_POST['first_page_link']);
} elseif (isset($_POST['previous_page'])) {
redirect_to($_POST['previous_page_link']);
}
}