'Last 7 days', 30 => 'Last 30 days', 90 => 'Last 90 days', 365 => 'Last year', 0 => 'Any time']; $days = isset($_GET['days']) && array_key_exists(intval($_GET['days']), $when_choices) ? intval($_GET['days']) : 30; // Only these sort - filter_header.php will hand through any lowercase word if (!in_array($sort, ['archived_at', 'archived_name', 'archived_kind', 'client_name'], true)) { $sort = 'archived_at'; } $union = archivedUnionSql($kind_filter ? [$kind_filter => $kinds[$kind_filter]] : $kinds, $days, $client_filter, $q); $sql = mysqli_query( $mysqli, "SELECT SQL_CALC_FOUND_ROWS archived.*, client_name FROM ($union) AS archived LEFT JOIN clients ON client_id = archived_client_id ORDER BY $sort $order, archived_at DESC LIMIT $record_from, $record_to" ); $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()")); $rows = []; while ($row = mysqli_fetch_assoc($sql)) { $rows[] = $row; } $archived_by = archivedBy($rows); $can_restore_any = (bool) $restore_kinds; // The clients with something archived, for the filter $client_options = []; $sql_clients = mysqli_query($mysqli, "SELECT DISTINCT client_id, client_name, client_abbreviation FROM (" . archivedUnionSql($kinds, $days) . ") AS archived JOIN clients ON client_id = archived_client_id ORDER BY client_name ASC"); while ($row = mysqli_fetch_assoc($sql_clients)) { $client_options[] = $row; } ?>