0) { $where[] = "b.location_id = ?"; $types .= "i"; $params[] = $locationId; } $whereSql = $where ? "WHERE " . implode(" AND ", $where) : ""; $buildings = $sql->get( "SELECT b.*, l.name AS location_name, COUNT(f.id) AS floor_count FROM buildings b LEFT JOIN locations l ON b.location_id = l.id LEFT JOIN floors f ON f.building_id = b.id $whereSql GROUP BY b.id ORDER BY l.name, b.name", $types, $params ); // ========================= // Filter-Daten // ========================= $locations = $sql->get("SELECT id, name FROM locations ORDER BY name", "", []); ?>