HI,
Not quite as simple as that =)
You need something like this: (it WON'T sort by age, I tried - but couldn't get it working)
Code:
sub {
use GT::SQL;
use lib '/path/to/secure_data/lib';
my $NEWDB = new GT::SQL (
def_path => '/path/to/secure_data/defs',
cache => 0,
debug => 0,
subclass => 0
);
my $db = $NEWDB->table('comm_users');
$db->select_options( "GROUP BY prof_birthday","ORDER BY dob_count DESC");
my $sth = $db->select("prof_birthday", "COUNT(*) as dob_count") or die "Query Error: $GT::SQL::error";
my $current = GT::Date::date_get();
my @current = split /-/, $current; # $current[0]
my $ages;
my $back;
while (my ($s, $c) = $sth->fetchrow_array) {
if ($s !~ /^(19|20)\d\d-/) { next; }
my @date = split /-/, $s; # yyyy-mm-dd
my $age = $current[0] - $date[0]; # age of person looking at
if ($ages->{$age}) { $ages->{$age} += 1; } else { $ages->{$age} = 1;}
}
my @entries;
map {
push @entries, { Age => $_, Count => $ages->{$_} }
} sort keys %$ages;
return { age_loop => \@entries }
}
Then call with:
Code:
<%global_name%>
<ul>
<%loop age_loop%>
<li><%Age%> - <%Count%></li>
<%endloop%>
</ul>
Hopefully thats ok
Cheers
Andy (mod)
andy@ultranerds.com Merry Xmas and a Happy New Year!
Want to give me something back for my help? Please see my
Amazon Wish List GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500) Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin |
Pre-Made Template Sets |
FREE GLinks Plugins! Custom Toolbar for IE and Firefox! -
Compare our different Plugin packages *new*
Free CSS Templates