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

Global for Top-5-Links special

Quote Reply
Global for Top-5-Links special
Hi,

i have a sweepstakes-portal and have in my Links-table a field called "euro" for the value of a sweepstake (e.g. 500).
And i have also a field called "month", in which i fill the month of a sweepstake (e.g. 09-2004).

So now i need a global, where i can define the top valuable 5 sweepstakes depending on month.

In informal language there are this steps:
- Search for the biggest X (e.g. 5) values of data-records where month = 09-2004 (e.g.)
- Print them out like sorted DESC by euros:

Top1: Title_1 - Description_2: 1200 Euros
Top2: Title_2 - Description_2: 1150 Euros
etc...

And so i start the global for example: <%global_name($5,$09-2004)%>

Thanks in advance!

Coyu
Quote Reply
Re: [Coyu] Global for Top-5-Links special In reply to
You can try something like this:

Code:

sub {
my $month = $_[0];
my $euro = $_[1];
my ($sth,$tab,$output);
$tab = $DB->table('Links');
$tab->select_options('ORDER BY euro where month=$month DESC LIMIT $euro');
$sth = $tab->select( { isValidated => 'Yes' } );
while (my $rec = $sth->fetchrow_hashref) {
$output .= Links::SiteHTML::display('euro_template_name', $rec);
}


and you would call it like <%global_name(09-2004, 5)%>

You will also have to creat a template for each of your link.

I'm not sure if that query is correct:

Hope this helps some,

- Jonathan
Quote Reply
Re: [jdgamble] Global for Top-5-Links special In reply to
Hi,
thank you very much fpr your help!

But: where i should store the templates and how the global knows, where they are?
Should i make an index?
template1, template2, etc... ?

Thanx in advance,
Greetings,

Coyu
Quote Reply
Re: [Coyu] Global for Top-5-Links special In reply to
Code:
$output .= Links::SiteHTML::display('euro_template_name', $rec);


This line tells it to load the links package and to display the euro_template_name(.html) as if it were any other links template. The template should be stored in the same directory as all of your other links templates. The (.html) is not needed because the package or module knows its extention.

Quote:

Should i make an index?
template1, template2, etc... ?


No, you do not need anything of the sort. Simply edit your euro_template.html template and everything you work the same way as any other template.

Hope this helps,

- Jonathan