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

Re: [Piers1] Show random paid link

Quote Reply
Re: [Piers1] Show random paid link In reply to
Hi,

Ok, try this:

Ok, you need 2 globals:

1) random_paid_in_category

Code:
sub {

my $cat = shift;
my $all_ids = $DB->table('Category')->children($cat);
push @$all_ids, $cat;

my $db_obj = $DB->table('Links','CatLinks','Category');
$db_obj->select_options ('ORDER BY Add_Date DESC LIMIT 1');

my $time = time;
my $cond = GT::SQL::Condition->new('CategoryID', 'IN', $all_ids);
my $cond2 = GT::SQL::Condition->new('isNew','=','Yes','isValidated','=','Yes','ExpiryDate','>', $time, 'ExpiryDate', '<', 2147483647);
my $sth = $db_obj->select (['Links.*'], $cond, $cond2 ) || die $GT::SQL::error;

my @links;
while (my $hit = $sth->fetchrow_hashref) {

if ($CFG->{build_detailed}) { $hit->{detailed_url} = $CFG->{build_root_url} . "/" . $DB->table('Links')->detailed_url( $hit->{ID} ); }

if ($hit->{isNew} eq "Yes") { $hit->{isNew} = 1; } else { $hit->{isNew} = 0; }
if ($hit->{isPopular} eq "Yes") { $hit->{isPopular} = 1; } else { $hit->{isPopular} = 0; }
if ($hit->{isChanged} eq "Yes") { $hit->{isChanged} = 1; } else { $hit->{isChanged} = 0; }

push @links, $hit;
}

return { random_link => \@links }

}


2) check_if_paid_exists

Code:
sub {

my $cat = shift;
my $all_ids = $DB->table('Category')->children($cat);
push @$all_ids, $cat;

my $db_obj = $DB->table('Links','CatLinks','Category');
$db_obj->select_options ('ORDER BY Add_Date DESC LIMIT 1');

my $time = time;
my $cond = GT::SQL::Condition->new('CategoryID', 'IN', $all_ids);
my $cond2 = GT::SQL::Condition->new('isNew','=','Yes','isValidated','=','Yes','ExpiryDate','>', $time, 'ExpiryDate', '<', 2147483647);
my $count = $db_obj->count ( $cond, $cond2 ) || die $GT::SQL::error;

return { num_paid_found => $count }

}

..then use this:

Code:
<%num_paid_found($category_id)%>
<%if num_paid_found > 0%>
. ..
<%endif%>


Then, call with:

Code:
<%check_if_paid_exists($category_id)%>
<%if num_paid_found > 0%>
<%random_paid_in_category($category_id)%>
<%if random_link.length%>
<%loop random_link%>
<%include nclude_paid_link.html%>
<%endif%>
<%endif%>
<%endif%>


Again, untested - but thats how I would use it (from the 2 globals above)

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!

Last edited by:

Andy: Apr 25, 2008, 2:59 AM
Subject Author Views Date
Thread Show random paid link wilhelm 17333 Nov 12, 2004, 11:24 AM
Post Re: [wilhelm] Show random paid link
katabd 16804 Mar 29, 2006, 7:53 AM
Thread Re: [wilhelm] Show random paid link
tandat 16821 Mar 29, 2006, 9:17 AM
Thread Re: [tandat] Show random paid link
katabd 16911 Mar 29, 2006, 8:44 PM
Thread Re: [katabd] Show random paid link
tandat 16940 Mar 30, 2006, 7:45 AM
Thread Re: [tandat] Show random paid link
katabd 16818 Mar 30, 2006, 7:54 AM
Thread Re: [katabd] Show random paid link
katabd 16841 Mar 30, 2006, 7:57 AM
Thread Re: [katabd] Show random paid link
katabd 16788 Apr 2, 2006, 7:50 PM
Thread Re: [katabd] Show random paid link
afinlr 16829 Apr 5, 2006, 4:49 AM
Thread Re: [afinlr] Show random paid link
katabd 16809 Apr 7, 2006, 9:18 PM
Post Re: [katabd] Show random paid link
afinlr 16743 Apr 8, 2006, 4:28 AM
Thread Re: [katabd] Show random paid link
katabd 16735 Apr 8, 2006, 7:45 AM
Thread Re: [katabd] Show random paid link
Piers1 16587 Apr 23, 2008, 12:44 PM
Thread Re: [Piers1] Show random paid link
Andy 16585 Apr 24, 2008, 1:01 AM
Thread Re: [Andy] Show random paid link
Piers1 16512 Apr 24, 2008, 4:55 AM
Post Re: [Piers1] Show random paid link
Andy 16518 Apr 24, 2008, 5:25 AM
Thread Re: [Piers1] Show random paid link
Andy 16540 Apr 24, 2008, 5:31 AM
Thread Re: [Andy] Show random paid link
Piers1 16538 Apr 24, 2008, 11:12 PM
Post Re: [Piers1] Show random paid link
Andy 16454 Apr 25, 2008, 12:37 AM
Thread Re: [Piers1] Show random paid link
Andy 16461 Apr 25, 2008, 1:03 AM
Thread Re: [Andy] Show random paid link
Piers1 16432 Apr 25, 2008, 2:51 AM
Thread Re: [Piers1] Show random paid link
Andy 16463 Apr 25, 2008, 3:01 AM
Thread Re: [Andy] Show random paid link
Piers1 16512 Apr 25, 2008, 3:23 AM
Thread Re: [Piers1] Show random paid link
Andy 16443 Apr 25, 2008, 3:30 AM
Thread Re: [Andy] Show random paid link
Piers1 16499 Apr 25, 2008, 3:39 AM
Thread Re: [Piers1] Show random paid link
Andy 8669 Apr 25, 2008, 4:18 AM
Thread Re: [Andy] Show random paid link
Piers1 8639 Apr 25, 2008, 12:32 PM
Thread Re: [Piers1] Show random paid link
Andy 8639 Apr 25, 2008, 12:45 PM
Thread Re: [Andy] Show random paid link
Piers1 8594 Apr 25, 2008, 1:13 PM
Thread Re: [Piers1] Show random paid link
Andy 8602 Apr 25, 2008, 1:16 PM
Thread Re: [Andy] Show random paid link
Piers1 8590 Aug 23, 2008, 5:18 AM
Thread Re: [Piers1] Show random paid link
Andy 8601 Aug 24, 2008, 6:09 AM
Thread Re: [Andy] Show random paid link
Piers1 8567 Aug 24, 2008, 11:16 AM
Thread Re: [Piers1] Show random paid link
Andy 8555 Aug 25, 2008, 1:07 AM
Thread Re: [Andy] Show random paid link
Piers1 8516 Aug 25, 2008, 3:36 AM
Thread Re: [Piers1] Show random paid link
Andy 8562 Aug 25, 2008, 3:46 AM
Thread Re: [Andy] Show random paid link
Piers1 8537 Aug 25, 2008, 4:31 AM
Post Re: [Piers1] Show random paid link
Andy 8490 Aug 25, 2008, 5:23 AM