From: Steinar H. Gunderson Date: Sun, 25 Mar 2012 15:12:21 +0000 (+0200) Subject: Factor out division-fetching code. X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=77b9653b9c3704f8ab67af7b2f1d85a256ac5ca2;hp=07a946e7bcebf9c7c0e2e94d0c923c87a740f474;p=wloh Factor out division-fetching code. --- diff --git a/www/index.pl b/www/index.pl index 06babf6..c63ae09 100755 --- a/www/index.pl +++ b/www/index.pl @@ -47,6 +47,21 @@ sub get_max_season { return $ref->{'max_sesong'}; } +sub get_divisions { + my ($dbh, $season) = @_; + + my @divisions = (); + + my $q = $dbh->prepare('SELECT DISTINCT(divisjon) FROM fotballserier WHERE sesong=? ORDER BY divisjon'); + $q->execute($season); + + while (my $ref = $q->fetchrow_hashref) { + push @divisions, $ref->{'divisjon'}; + } + + return @divisions; +} + sub make_table { my ($lowest_division, $used_ratings, $used_cov) = @_; @@ -191,31 +206,23 @@ printf <<"EOF", $match_stddev; EOF my $season = get_max_season($dbh); +my @divisions = get_divisions($dbh, $season); +$division = 1 if (!grep { $_ == $division } @divisions); +my $max_division = $divisions[$#divisions]; print <<"EOF";

Divisjon: Avdeling: