Gossamer Forum
Quote Reply
random id global
hi,

first, please excuse my bad english!

i search a global, to show a random link id.

i have found many random link globals, but no one returns only the id.

have anybody something?

Last edited by:

regatta: Apr 25, 2005, 5:04 AM
Quote Reply
Re: [regatta] random id global In reply to
Hi,

Give this a go;

<%rand_link%>

Code:
sub {
my $db = $DB->table('Links');
$db->select_options("LIMIT 1");
my $linkid = $db->select( ['RAND(ID)'] )->fetchrow || return $GT::SQL::error;
my $link = $db->get( $linkid );
return Links::SiteHTML::display('link', $link);
}

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 id global In reply to
thanks andy,

but it doesnt returns the link id.

i want only a random link id.
Quote Reply
Re: [regatta] random id global In reply to
To return just the link ID, you could use;

Code:
sub {
my $db = $DB->table('Links');
$db->select_options("LIMIT 1");
my $linkid = $db->select( ['RAND(ID)'] )->fetchrow || return $GT::SQL::error;
return $linkid ;
}

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 id global In reply to
hi andy,

thanks fŘr your answer, but in your global must be an error!

the global returns on every site 0.18109050223705
Quote Reply
Re: [regatta] random id global In reply to
Try this. It's from Jump.pm

Code:
sub {
my $db = $DB->table('Links');
my $total = $db->total() - $db->count({ isValidated => 'No' });
my $offset = int rand $total;
$db->select_options ("LIMIT $offset, 1");
my $sth = $db->select ( { isValidated => 'Yes'} , ['ID']);
my ($id) = $sth->fetchrow_array;
return ($id);
}

It doesn't rely on the RAND function in queries.


PUGDOG´┐Ż Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.

Last edited by:

pugdog: Apr 25, 2005, 6:05 PM
Quote Reply
Re: [pugdog] random id global In reply to
hi pugdog,

now there's an error "unable to compile..."

i think, my wish is impossible!

thanks

Last edited by:

regatta: Apr 25, 2005, 9:19 AM
Quote Reply
Re: [regatta] random id global In reply to
Hi,

for some reason the cut/paste was not the updated one, but the previous one.

The code has been fixed, and is working for me on a GL3 site.


PUGDOG´┐Ż Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Quote Reply
Re: [pugdog] random id global In reply to
hi pugdog,


great. it works.

thanks