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.
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')) | | ($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/
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')) | | ($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/