Kleine Änderungen
This commit is contained in:
35
zahler.php
Executable file
35
zahler.php
Executable file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
function get_next_payer_username($conn, $meeting_id)
|
||||
{
|
||||
$sql = "
|
||||
SELECT
|
||||
u.username,
|
||||
(SELECT COUNT(*) FROM meeting_teilnehmer WHERE user_id = u.id AND paid = 1) AS paid_count
|
||||
FROM meeting_teilnehmer mt
|
||||
JOIN users u ON mt.user_id = u.id
|
||||
WHERE mt.meeting_id = ? AND mt.rsvp_status = 'accepted'
|
||||
ORDER BY paid_count ASC
|
||||
";
|
||||
$stmt = mysqli_prepare($conn, $sql);
|
||||
if (!$stmt) return null;
|
||||
|
||||
mysqli_stmt_bind_param($stmt, "i", $meeting_id);
|
||||
mysqli_stmt_execute($stmt);
|
||||
$result = mysqli_stmt_get_result($stmt);
|
||||
|
||||
$candidates = [];
|
||||
$min_count = -1;
|
||||
while ($row = mysqli_fetch_assoc($result)) {
|
||||
if ($min_count == -1 || $row['paid_count'] < $min_count) {
|
||||
$min_count = $row['paid_count'];
|
||||
$candidates = [$row['username']];
|
||||
} elseif ($row['paid_count'] == $min_count) {
|
||||
$candidates[] = $row['username'];
|
||||
}
|
||||
}
|
||||
mysqli_stmt_close($stmt);
|
||||
|
||||
if (empty($candidates)) return null;
|
||||
sort($candidates);
|
||||
return $candidates[0];
|
||||
}
|
||||
Reference in New Issue
Block a user