My Code:
JavaScript
x
for ($i = 0, $anzZeilen = count($zeilen); $i < $anzZeilen; $i++) {
switch ($zeilen[$i]['satzart']) {
case 10: // Bundesland
satz10($db, $zeilen[$i]);
break;
case 40: // Landkreis
satz40($db, $zeilen[$i]);
break;
case 60: // Kommune
satz60($db, $zeilen[$i]);
break;
}
}
My test output (a small excerpt):
JavaScript
int(60)
Quelle :Ofterdingen | Rohdaten Ofterdingen | bereinigt :Ofterdingen | ohne sorbisch :Ofterdingen | ohne , :Ofterdingen
int(60)
Quelle :Rottenburg am Neckar, Stadt |
int(60)
Quelle :Tübingen, Universitätsstadt |
int(60)
Quelle :Ammerbuch | Rohdaten Ammerbuch | bereinigt :Ammerbuch | ohne sorbisch :Ammerbuch | ohne , :Ammerbuch
The corresponding variable is integer and 60. | dump($zeilen[$i][‘satzart’])
And I have no idea why the function satz60() is not executed. (This can be seen in the test output, that no further values are output.)
It is not relevant because I did a test output before calling satz60(), but this is what the code of the called function looks like including auxiliary outputs.
JavaScript
function satz60(PDO $db, array $zeilen)
{
$bundeslandDestatis = (int) substr($zeilen['region'],0,2);
$landkreisDestatis = (int) substr($zeilen['region'],2,3);
$gebietsForm = (int) $zeilen['schluessel'];
if (in_array($gebietsForm, [60,61,62,63,64])) {
$gemeindeName = bereinigeGebietsname($zeilen['bezeichnung1']);
echo ' Rohdaten '.$zeilen['bezeichnung1'].' | bereinigt :'.$gemeindeName.' | ohne sorbisch :';
// Namenszusätze entfernen - sorbisch
if (strpos($gemeindeName, ' / ') > 0 ) {
$gemeindeName = substr($gemeindeName,0,strpos($gemeindeName, ' / ')) ;
}
echo $gemeindeName.' | ohne , :';
// Namenszusätze nach dem , entfernen
if (strpos($gemeindeName, ', ') > 0 ) {
$gemeindeName = substr($gemeindeName,0,strpos($gemeindeName, ', ')) ;
}
echo $gemeindeName.'<br>';
$query = 'SELECT * FROM `destatis_landkreis` WHERE `landkreis_destatis` = ''.$landkreisDestatis.'' AND `bundesland_destatis`= ''.$bundeslandDestatis.''';
$select = $db->query($query);
$landkreis = $select->fetch();
if (!$landkreis['kreisfrei']) {
$k = 1;
while ($k < 246) {
$spalte = 'LKM'.$k;
if (empty($landkreis[$spalte])) {
$sql2 = 'UPDATE `destatis_landkreis` SET `LKM'.$k.'`= ? WHERE `landkreis_destatis`= ? AND `bundesland_destatis`=?';
$statement = $db->prepare($sql2);
$statement->execute([$gemeindeName,$landkreisDestatis,$bundeslandDestatis]);
$k = 246;
}
$k++;
}
}
}
}
Extract from $zeilen – raw data
JavaScript
6020210131084160315002Ofterdingen 64 000000015150000000518200000002581 72131 2886270766417290
6020210131084160365003Rottenburg am Neckar, Stadt 67 000000142260000004384300000021763 72108 2886270666417290
6020210131084160410041Tübingen, Universitätsstadt 67 000000108060000009150600000043546 72070***** 2886270766417290
6020210131084160480048Ammerbuch 64 000000048040000001130200000005610 72119***** 2886270766417290
Advertisement
Answer
My error is in the line
JavaScript
if (in_array($gebietsForm, [60,61,62,63,64])) {
In the source file there are further area forms, which did not appear in the file description.
So it must be -without further check-:
JavaScript
if (in_array($gebietsForm, [60,61,62,63,64,65,66,67,68,69])) {