Alle = $personMehrzahl ?>:
prepare($sql);
if (!$stmt->execute()) {
http_response_code(500);
exit;
}
// get result set
$result = $stmt->get_result();
// fetch all rows as associative array
$entries = $result->fetch_all(MYSQLI_ASSOC);
$stmt->close();
// Filter for non-admins
if (!$isAdmin) {
$entries = array_filter($entries, function ($row) use ($selectedverein) {
return $row['verein'] === $selectedverein;
});
}
$grouped = [];
foreach ($entries as $entry) {
$key = $entry['programm'];
$grouped[$key][] = $entry;
}
$idsEntriesArray = array_column($entries, 'id');
$placeholders = '';
if (!empty($idsEntriesArray)) {
$placeholders = implode(', ', array_fill(0, count($idsEntriesArray), '?'));
$sqlQuery = "SELECT
paf.`person_id`,
paf.`geraet_id`,
paf.`audiofile_id`,
af.`file_name`,
af.`file_path`
FROM $tableTeilnehmendeAudiofiles paf
LEFT JOIN $tableAudiofiles af
ON af.`id` = paf.`audiofile_id`
WHERE paf.`person_id` IN ($placeholders)
";
$stmt = $mysqli->prepare($sqlQuery);
$stmt->bind_param(str_repeat('i', count($idsEntriesArray)), ...$idsEntriesArray);
$stmt->execute();
$result = $stmt->get_result();
$audiofilesPersonen = $result->fetch_all(MYSQLI_ASSOC);
$stmt->close();
$indexedAudiofilesPersonen = [];
foreach ($audiofilesPersonen as $sAf) {
$indexedAudiofilesPersonen[$sAf['person_id']][$sAf['geraet_id']] = ["audiofile_id" => $sAf['audiofile_id'], "file_name" => $sAf['file_name'], "file_path" => $sAf['file_path']];
}
}
// Sort the grouped keys by defined priority
uksort($grouped, function ($a, $b) use ($sortprio) {
$a_index = array_search($a, $sortprio);
$b_index = array_search($b, $sortprio);
$a_index = $a_index === false ? PHP_INT_MAX : $a_index;
$b_index = $b_index === false ? PHP_INT_MAX : $b_index;
return $a_index <=> $b_index;
});
$total_count = 0;
$invalidProgrammes = false;
if (!empty($grouped)): ?>
Noch keine Datensätze vorhanden.
displayMsg(' . (int)$_SESSION['form_message_type'] . ', "' . $_SESSION['form_message'] . '");';
unset($_SESSION['form_message']);
unset($_SESSION['form_message_type']);
}
?>