return @divisions;
}
+sub get_subdivisions {
+ my ($dbh, $season, $division) = @_;
+
+ my @subdivisions = ();
+
+ my $q = $dbh->prepare('SELECT DISTINCT(avdeling) FROM fotballserier WHERE sesong=? AND divisjon=? ORDER BY avdeling');
+ $q->execute($season, $division);
+
+ while (my $ref = $q->fetchrow_hashref) {
+ push @subdivisions, $ref->{'avdeling'};
+ }
+
+ return @subdivisions;
+}
+
sub make_table {
my ($lowest_division, $used_ratings, $used_cov) = @_;
<select name="avdeling" onchange="form.submit();">
EOF
-$q = $dbh->prepare('SELECT DISTINCT(avdeling) FROM fotballserier WHERE sesong=? AND divisjon=? ORDER BY avdeling');
-$q->execute($season, $division);
-
-my $found_subdivision = 0;
+my @subdivisions = get_subdivisions($dbh, $season, $division);
+$subdivision = 1 if (!grep { $_ == $subdivision } @subdivisions);
-while (my $ref = $q->fetchrow_hashref) {
- my $sd = $ref->{'avdeling'};
+for my $sd (@subdivisions) {
if ($sd == $subdivision) {
print " <option value=\"$sd\" selected=\"selected\">$sd</option>\n";
- $found_subdivision = 1;
} else {
print " <option value=\"$sd\">$sd</option>\n";
}
}
-$subdivision = 1 if (!$found_subdivision);
-
print <<"EOF";
</select>
<input type="submit" value="Vis" />