Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

Re: [Matthias70] Global: List where the users come from?

Quote Reply
Re: [Matthias70] Global: List where the users come from? In reply to
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 Tongue

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Subject Author Views Date
Thread; hot thread Global: List where the users come from? Matthias70 11654 Dec 23, 2007, 2:54 AM
Thread; hot thread Re: [Matthias70] Global: List where the users come from?
Andy 11421 Dec 23, 2007, 3:23 AM
Thread; hot thread Re: [Andy] Global: List where the users come from?
Matthias70 11401 Dec 23, 2007, 3:39 AM
Thread; hot thread Re: [Matthias70] Global: List where the users come from?
Andy 11428 Dec 23, 2007, 3:47 AM
Thread; hot thread Re: [Andy] Global: List where the users come from?
Matthias70 11449 Dec 23, 2007, 3:52 AM
Thread; hot thread Re: [Matthias70] Global: List where the users come from?
Andy 11447 Dec 23, 2007, 3:58 AM
Thread; hot thread Re: [Andy] Global: List where the users come from?
Matthias70 11445 Dec 23, 2007, 4:03 AM
Thread; hot thread Re: [Matthias70] Global: List where the users come from?
Andy 11382 Dec 23, 2007, 4:05 AM
Thread; hot thread Re: [Andy] Global: List where the users come from?
Matthias70 11549 Dec 23, 2007, 4:09 AM
Thread; hot thread Re: [Matthias70] Global: List where the users come from?
Andy 11423 Dec 23, 2007, 4:14 AM
Thread; hot thread Re: [Andy] Global: List where the users come from?
Matthias70 11432 Dec 23, 2007, 4:18 AM
Thread; hot thread Re: [Matthias70] Global: List where the users come from?
Andy 11437 Dec 23, 2007, 4:19 AM
Thread; hot thread Re: [Andy] Global: List where the users come from?
Matthias70 11394 Dec 23, 2007, 10:57 AM
Thread; hot thread Re: [Matthias70] Global: List where the users come from?
Matthias70 11427 Dec 25, 2007, 12:33 PM
Thread; hot thread Re: [Matthias70] Global: List where the users come from?
Andy 11392 Dec 26, 2007, 12:40 AM
Thread; hot thread Re: [Andy] Global: List where the users come from?
Matthias70 11305 Dec 29, 2007, 12:14 PM
Thread; hot thread Re: [Matthias70] Global: List where the users come from?
Andy 11329 Dec 29, 2007, 12:33 PM
Thread; hot thread Re: [Andy] Global: List where the users come from?
Matthias70 11352 Dec 31, 2007, 6:25 AM
Post; hot thread Re: [Matthias70] Global: List where the users come from?
Andy 11301 Dec 31, 2007, 6:30 AM
Thread; hot thread Re: [Andy] Global: List where the users come from?
Matthias70 11306 Mar 23, 2008, 6:57 AM
Thread; hot thread Re: [Matthias70] Global: List where the users come from?
Andy 11285 Mar 23, 2008, 7:30 AM
Post; hot thread Re: [Andy] Global: List where the users come from?
Matthias70 11296 Mar 23, 2008, 8:37 AM