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

Count-Global with conditions

Quote Reply
Count-Global with conditions
Hi,
how can i add into this global conditions?

Code:

sub {
my ($total) = $DB->table('Users')->select(['COUNT(Logins)'])->fetchrow_array;
return $total;
}

for example i need only to count this, when Status eq 'Administrator' and Logins >= 3.
How can i easily add conditions into the upper global?

And: How can i make the table open? So that i can start the global including the variabel like this:
<%counter('Users')%>

Thanks in advance!

Coyu
Quote Reply
Re: [Coyu] Count-Global with conditions In reply to
Code:
my $cond = new GT::SQL::Condition;
$cond->add('Field','=','something');
$cond->add('ID','>','10');
my ($total) = $DB->table('Users')->select(['COUNT(Logins)'],$cond)->fetchrow_array;

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!
Quote Reply
Re: [Andy] Count-Global with conditions In reply to
Hi Andy, thanx!
It works very fine!

Two little things: How i use an "OR" between two conditions?

And: How i can summarize the globals (<%counter1%>) in a template?
This two alternatives doesnt works:

<%set new = $counter1 + $counter2 + $counter3 + $counter4%>
<%neu%>

or

<%$counter1 + $counter2 + $counter3 + $counter4%>

How can i summarize counter without using a global?

I am using for counting your global called counter1:
Code:

sub {
my $cond = new GT::SQL::Condition;
$cond->add('GS_Status','=','bezahlt');
my ($total) = $DB->table('Prod_GS')->select(['COUNT(Username)'],$cond)->fetchrow_array;
return $total;
}

Thanks in advance!

Coyu
Quote Reply
Re: [Coyu] Count-Global with conditions In reply to
Quote:
Two little things: How i use an "OR" between two conditions?

Code:
sub {
my $cond = new GT::SQL::Condition;
$cond->bool('OR');
$cond->add('GS_Status','=','bezahlt');
my ($total) = $DB->table('Prod_GS')->select(['COUNT(Username)'],$cond)->fetchrow_array;
return $total;
}


Quote:
How can i summarize counter without using a global?

Not sure. The way I would do it, is;

<%global_name($count1,$counter2,$counter3,$count4)%>

Code:
sub { return $_[0] + $_[1] + $_[2] + $_[3] }

Hope that helps.

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!
Quote Reply
Re: [Andy] Count-Global with conditions In reply to
Hey Andy, that works too! ,-) THANKS!!!

A last question:
How can i make the table and the conditions as parameters?
So i can call a "meta"-global like:
<%count(table_name,cond_fieldname,cond_operator,cond_fieldvalue,cond_countfor)%>

Of course this should be work with ONE condition, otherwise it would be very complicated!

How should i change your global?
Code:

sub {
my $cond = new GT::SQL::Condition;
$cond->add('cond_Fieldname','cond_operator','cond_fieldvalue');
my ($total) = $DB->table('table_name')->select(['COUNT(cond_countfor)'],$cond)->fetchrow_array;
return $total;
}

Thanks in advance!

Coyu