Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Random New Link

Quote Reply
Random New Link
I want to make a global that pops out a random link from all those added in the current month. Here is the global I wrote: ('date_user_format_one' is definded as "%yyyy%-%mm%" in config...)

sub {
my $db = $DB->table('Links');
Links::init_date();
GT::Date::date_set_format($CFG->{'date_user_format_one'});
my $to_date = GT::Date::date_get();
GT::Date::date_set_format($CFG->{'date_db_format'});
my $cond = GT::SQL::Condition->new(
'isValidated', '=', 'Yes',
'Add_Date', 'LIKE', '$to_date%'
);

my $total = $db->count ( $cond );
my $rand = int( rand($total) );
$db->select_options ("LIMIT $rand, 1");
my $link = $db->select->fetchrow_hashref;
my $html = Links::SiteHTML::display('link', $link);
return $html;
}

OK, I tested, and $to_date works fine- it returns 2004-03 right now. But the global as a whole always returns the same ONE record, and one NOT entered in the current month.

Anyone see what I might have done wrong here

TIA
dave

Big Cartoon DataBase
Big Comic Book DataBase
Quote Reply
Re: [carfac] Random New Link In reply to
$cond is missing from from your select statement... try:

Code:
my $link = $db->select($cond)->fetchrow_hashref;

Philip
------------------
Limecat is not pleased.
Quote Reply
Re: [carfac] Random New Link In reply to
Also, you sure you don't need to use this;

Code:
'Add_Date', 'LIKE', "$to_date%"

Not the use of " " and not ' ' (which would, in theory stop the variable being read).

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] Random New Link In reply to
Fuzzy:

Thanks- I was JUST about to post that, no, that did not quite do it, when I spotted Eagle-Eyes Adny's post! That did it Andy- thank you!!!!
dave

Big Cartoon DataBase
Big Comic Book DataBase
Quote Reply
Re: [carfac] Random New Link In reply to
Quote:
when I spotted Eagle-Eyes Adny's post! That did it Andy- thank you!!!!

Glad its working :)

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!