Gossamer Forum
Home : Products : Gossamer Links : Version 1.x :

Excluding some sites from "random" jumps

Quote Reply
Excluding some sites from "random" jumps
Since people seem to be doing a lot of coding, I thought I'd put some of the ideas I've been using on-line just to see if they help anyone.

This inserts a block of code into jump.cgi that ignores URL's in a certain range. For me, I had installed a bunch of affiliate programs, and didn't want people jumping to them. It's always a good idea to put a limit on a loop, especially when debugging, so you don't get an endless loop -- hence the 'tries' variable. After 5 tries, it just goes through.

Code:
# If we are chosing a random link, then get the total and go to one at random.
if ($id eq "random") {
$total = $db->total();
$offset = int rand $total;
my $check_cat = '20'; ##_## set the test
my $tries = '0';
until ((($check_cat < '16') && ($check_cat > '37')) &#0124; &#0124; ($tries > '5')) {

$sth = $db->prepare ( " SELECT * FROM Links LIMIT $offset, 1 ");
$sth->execute() or die $DBI::errstr;

$rec = $sth->fetchrow_hashref;

$check_cat = $rec=>{'CategoryID'}; ##_## if not a shopping site, will fall through
$tries++;
$offset = int rand $total; ##_## set up for next pass
}

$goto = $rec->{'URL'};


------------------
POSTCARDS.COM -- Everything Postcards on the Internet www.postcards.com
LinkSQL FAQ: www.postcards.com/FAQ/LinkSQL/








Quote Reply
Re: Excluding some sites from "random" jumps In reply to
Yeah I was thinking about doing something like that...though I was thinking about removing the random feature altogether because alot of my 'links' don't even have a URL associated with them. Have you already got something done that would keep a 'link' from being used if the URL is NULL? I know it's not a hard mod but I've got so much more on my plate, I'd really love to add in something like that without doing it myself if it's already been done... Wink that is if you don't mind sharing!
Quote Reply
Re: Excluding some sites from "random" jumps In reply to
All you'd need to do is add another test to the "if" such that if the URL was equal to '' you failed the test and picked another random URL.

Not hard at all.

Code:
until ((($check_cat < '16') && ($check_cat > '37') && ($rec->{'URL'} != '')) &#0124; &#0124; ($tries > '5')) {

That said... no guarantee this will work! I just did it off the top of my head, and didn't test it, but the logic is:

if the ID is NOT between a range of IDs, AND the URL is NOT equal to null, AND the number of tries is NOT > 5, you'll keep it, otherwise you'll pick a new ID/URL.

You could probably set the test up differently, but but idea is a validity check on the link (ID and URL) the second check is whether we are begining to go in circles and just abort....

If you find that tries > 5 often enough, you can direct a user to a default page, and let them pick again, or to a specific link....

Quote Reply
Re: Excluding some sites from "random" jumps In reply to
Cool thanks...I'll give it a try tomorrow, and let you know!
Quote Reply
Re: Excluding some sites from "random" jumps In reply to
Hey Frown I'm trying to tackle this one in the SQL statement by making it more choosy about which one it grabs. I don't know if I'm doing this right because I don't have a SQL book yet...

But in this SELECT Statement, it should be an easy matter to only pull out * if URL isn't empty, Though I'm not sure what the syntax would be? Is it:

SELECT * FROM Links WHERE URL != '' LIMIT $offset, 1

This made sense but it doesn't seem to work?
Quote Reply
Re: Excluding some sites from "random" jumps In reply to
I got it to work...but I'd really rather be doing it the SQL statement! This was an interesting little assignment that gave me some good insight into a couple other things, so even though it was an easy little thing I gained some good experience. But Here I am sitting on a Random Link that now could take upto 25 SQL Calls to get a valid URL...I had to set it that high because I wasn't guaranteed a valid URL in the first 20 results, that's how few of my 'links' have URL's.
Quote Reply
Re: Excluding some sites from "random" jumps In reply to
Code:
SELECT * FROM Links WHERE URL != '' LIMIT $offset, 1

If your external URL's all have http:// in front of them, try this:

Code:
SELECT * FROM Links WHERE URL RLIKE 'http' LIMIT $offset, 1

I've found quirks in the queries, and have not had much luck with the Limit command at all... but that may just be me.



------------------
POSTCARDS.COM -- Everything Postcards on the Internet www.postcards.com
LinkSQL FAQ: www.postcards.com/FAQ/LinkSQL/








Quote Reply
Re: Excluding some sites from "random" jumps In reply to
I think I figured this out and why it wouldn't work...
The $offset is specifying the Link ID to fetch, so the Statement returns NULL if that particular record doesn't have an http, I tried that exact query from having seen you post the thing about RLIKE before, and thought it would be worth a shot, I think the way to do this would be to get the Links with valid URL's into a Hash and then randomly pick one of those...