138 lines
4.7 KiB
PHP
138 lines
4.7 KiB
PHP
<!DOCTYPE html>
|
|
<html lang="de">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<title>Fahrrad-Unfallstatistik NRW</title>
|
|
<link rel="stylesheet" href="../css/bootstrap.min.css"/>
|
|
<link rel="stylesheet" href="../css/jquery.dataTables.min.css">
|
|
|
|
<script src="../js/jquery.min.js"></script>
|
|
<script src="../js/bootstrap.min.js"></script>
|
|
<script src="../js/jquery.dataTables.min.js"></script>
|
|
<style>
|
|
.rechts {text-align:right;background-color:#eee;}
|
|
.l {border-left: 1px solid black; }
|
|
/* Sehr kleine Schrift für Tabelle */
|
|
#unfallzahlen {
|
|
font-size: 11px;
|
|
}
|
|
|
|
/* Optional: kleinere Schrift auch für Paginierung, Filter, usw. */
|
|
.dataTables_wrapper {
|
|
font-size: 11px;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<?php
|
|
|
|
require("../config.php");
|
|
// Hilfsfunktionen
|
|
function jahresHeader($von, $bis, $mitRand = false) {
|
|
$html = "";
|
|
for ($y = $von; $y >= $bis; $y--) {
|
|
$class = ($y == $von && $mitRand) ? " class='l'" : "";
|
|
$html .= "<th{$class}>{$y}</th>";
|
|
}
|
|
return $html;
|
|
}
|
|
function jahresSpaltenSQL($prefix, $von, $bis, $bedingung = "") {
|
|
$cols = [];
|
|
for ($y = $von; $y >= $bis; $y--) {
|
|
$cond = $bedingung ? " AND {$bedingung}" : "";
|
|
$cols[] = "SUM(UJAHR={$y}{$cond}) as {$prefix}_{$y}";
|
|
}
|
|
return implode(",\n ", $cols);
|
|
}
|
|
function jahresZellen($row, $prefix, $von, $bis) {
|
|
$html = "";
|
|
for ($y = $von; $y >= $bis; $y--) {
|
|
$class = ($y == $von) ? " class='l'" : "";
|
|
$html .= "<td{$class}>" . $row["{$prefix}_{$y}"] . "</td>";
|
|
}
|
|
return $html;
|
|
}
|
|
|
|
?>
|
|
|
|
<?php include("navbar.php"); ?>
|
|
|
|
|
|
<div class="container-fluid" style="margin-top:4em;">
|
|
<h1>Fahrradunfälle in Nordrhein-Westfalen in Gemeinden</h2>
|
|
<table id="unfallzahlen" class="display">
|
|
<thead>
|
|
<tr>
|
|
<th></th>
|
|
<th colspan="<?= $numLatestYear - $numStartYear + 1 ?>">Fahrradunfälle</th>
|
|
<th colspan="<?= $numLatestYear - $numStartYear + 1 ?>">Todesfälle</th>
|
|
<th colspan="<?= $numLatestYear - $numStartYear + 1 ?>">Schwerverletzte</th>
|
|
<th colspan="<?= $numLatestYear - $numStartYear + 1 ?>">Leichtverletzte</th>
|
|
<th class='l'>Fläche</th>
|
|
<th>Einw.</th>
|
|
<th>Quote</th>
|
|
</tr>
|
|
<tr>
|
|
<th>Name</th>
|
|
<?= jahresHeader($numLatestYear, $numStartYear, true) ?>
|
|
<?= jahresHeader($numLatestYear, $numStartYear, true) ?>
|
|
<?= jahresHeader($numLatestYear, $numStartYear, true) ?>
|
|
<?= jahresHeader($numLatestYear, $numStartYear, true) ?>
|
|
<th class='l' colspan="2">in Tausend</th>
|
|
<th></th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php
|
|
|
|
|
|
|
|
$strSQL = "SELECT d.Name as Gemeinde,
|
|
" . jahresSpaltenSQL('Jahr', $numLatestYear, $numStartYear) . ",
|
|
" . jahresSpaltenSQL('Tode', $numLatestYear, $numStartYear, 'UKATEGORIE=1') . ",
|
|
" . jahresSpaltenSQL('Schwerverletzt', $numLatestYear, $numStartYear, 'UKATEGORIE=2') . ",
|
|
" . jahresSpaltenSQL('Leichtverletzt', $numLatestYear, $numStartYear, 'UKATEGORIE=3') . ",
|
|
Flaeche, Einwohner,
|
|
SUM(UJAHR={$numLatestYear})/d.Einwohner*1000 as Quote_{$numLatestYear},
|
|
d.ULAND, d.UREGBEZ, d.UKREIS, d.UGEMEINDE
|
|
FROM data s, community d
|
|
WHERE IstRad=1
|
|
AND d.ULAND=s.ULAND AND d.UREGBEZ=s.UREGBEZ AND d.UKREIS=s.UKREIS AND d.UGEMEINDE=s.UGEMEINDE
|
|
GROUP BY s.ULAND, s.UREGBEZ, s.UKREIS, s.UGEMEINDE
|
|
ORDER BY Quote_{$numLatestYear} DESC";
|
|
|
|
// --- ORDER BY s.ULAND, s.UREGBEZ, s.UKREIS,s.UGEMEINDE
|
|
|
|
$result=$db->query($strSQL);
|
|
|
|
while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
|
|
echo "<tr>";
|
|
echo "<td><a href='gemeinde_details.php?regbez=".$row['UREGBEZ']."&kreis=".$row['UKREIS']."&gemeinde=".$row['UGEMEINDE']."'>".$row['Gemeinde']."</a></td>";
|
|
echo jahresZellen($row, 'Jahr', $numLatestYear, $numStartYear);
|
|
echo jahresZellen($row, 'Tode', $numLatestYear, $numStartYear);
|
|
echo jahresZellen($row, 'Schwerverletzt', $numLatestYear, $numStartYear);
|
|
echo jahresZellen($row, 'Leichtverletzt', $numLatestYear, $numStartYear);
|
|
echo "<td class='rechts l'>".$row['Flaeche']."</td>";
|
|
echo "<td class='rechts'>".round($row['Einwohner']/1000,1)."</td>";
|
|
echo "<td class='rechts'>".round($row["Quote_{$numLatestYear}"],2)."</td>";
|
|
echo "</tr>\n";
|
|
}
|
|
|
|
?>
|
|
</tbody>
|
|
</table>
|
|
|
|
</div>
|
|
</body>
|
|
<script>
|
|
let table = new DataTable('#unfallzahlen',{
|
|
pageLength : 10,
|
|
language: {
|
|
url: '../js/de-DE.json'
|
|
}
|
|
});
|
|
</script>
|
|
</html>
|