Gossamer Forum
Home : Products : Links 2.0 : Customization :

Random Order of Links -- Code

Quote Reply
Random Order of Links -- Code
Hi eeryone,

Its been a while because school is just keeping me busy. I noticed some people wanted random order and I used Alex's code. It works fine but some people still had problems with it.. Anyways Here is my whole build_sort_hit sub routine

Start
------------------------
my (@unsorted) = @_;
my ($num) = ($#unsorted+1) / ($#db_cols+1);
my (%sortby, %isnew, %iscool, $hit, $i, @sorted);

for ($i = 0; $i < $num; $i++) {
$sortby{$i} = $unsorted[$db_sort_links + ($i * ($#db_cols+1))];
if ($unsorted[$db_isnew + ($i * ($#db_cols+1))] eq "Yes") { $isnew{$i} = 1; }
if ($unsorted[$db_ispop + ($i * ($#db_cols+1))] eq "Yes") { $iscool{$i} = 1; }
}
srand;
foreach $hit (sort { return int(rand(1) + 0.5) ? 1 : -1 } (keys %sortby)) {

$first = ($hit * $#db_cols) + $hit;
$last = ($hit * $#db_cols) + $#db_cols + $hit;
push (@sorted, @unsorted[$first .. $last]);
}
return @sorted;
}
----------------------
END!

Hope it helps,
Vivitron
Quote Reply
Re: Random Order of Links -- Code In reply to
vivitron,

I believe that your code is exactly what I am looking for. As silly as it sounds what do I do whith it. were does it go and does it replace anything in my code. I assume this is an addition to me db.pl but that is about all the more I think I am sure of.

------------------
Thanks for all the help.
Quote Reply
Re: Random Order of Links -- Code In reply to
Replace your build_sorthit routine in db.pl with the code supplied.

Cheers,

Alex
Quote Reply
Re: Random Order of Links -- Code In reply to
Yo....... Frown I went to find the build_sorthit routine as well as the build_sort_hit routine in a text search in db.pl to find this so I could implement this mod, and it gave me a "text not found" on both of them. What needs to be replaced and where?

Frown *fret-fret-fret* Frown

Never mind. I found it in db_utils.pl not db.pl

------------------

--Sanguinarius
The Real Vampire Directory
www.sanguinarius.org/cgi-bin/links/pages/


[This message has been edited by Sanguinarius (edited September 01, 1999).]
Quote Reply
Re: Random Order of Links -- Code In reply to
OK,

In db_utils.pl in the sub build_sorthit, I replaced:

Quote:
my (@unsorted) = @_;
my ($num) = ($#unsorted+1) / ($#db_cols+1);
my (%sortby, %isnew, %iscool, $hit, $i, @sorted);

for ($i = 0; $i < $num; $i++) {
$sortby{$i} = $unsorted[$db_sort_links + ($i * ($#db_cols+1))];
($unsorted[$db_isnew + ($i * ($#db_cols+1))] eq "Yes") and ($isnew{$i} = 1);
($unsorted[$db_ispop + ($i * ($#db_cols+1))] eq "Yes") and ($iscool{$i} = 1);
}
foreach $hit (sort {
($isnew{$b} and !$isnew{$a}) and return 1;
($isnew{$a} and !$isnew{$b}) and return -1;
($iscool{$b} and !$iscool{$a}) and return 1;
($iscool{$a} and !$iscool{$b}) and return -1;
($isnew{$a} and $isnew{$b}) and return lc($sortby{$a}) cmp lc($sortby{$b});
($iscool{$a} and $iscool{$b}) and return lc($sortby{$a}) cmp lc($sortby{$b});
return lc($sortby{$a}) cmp lc($sortby{$b});
} (keys %sortby)) {
$first = ($hit * $#db_cols) + $hit;
$last = ($hit * $#db_cols) + $#db_cols + $hit;
push (@sorted, @unsorted[$first .. $last]);
}
return @sorted;
}

(which is the code that Links came with) with:

Quote:
my (@unsorted) = @_;
my ($num) = ($#unsorted+1) / ($#db_cols+1);
my (%sortby, %isnew, %iscool, $hit, $i, @sorted);

for ($i = 0; $i < $num; $i++) {
$sortby{$i} = $unsorted[$db_sort_links + ($i * ($#db_cols+1))];
if ($unsorted[$db_isnew + ($i * ($#db_cols+1))] eq "Yes") { $isnew{$i} =
1; }
if ($unsorted[$db_ispop + ($i * ($#db_cols+1))] eq "Yes") { $iscool{$i}
= 1; }
}
srand;
foreach $hit (sort { return int(rand(1) + 0.5) ? 1 : -1 } (keys
%sortby)) {

$first = ($hit * $#db_cols) + $hit;
$last = ($hit * $#db_cols) + $#db_cols + $hit;
push (@sorted, @unsorted[$first .. $last]);
}
return @sorted;
}

and then uploaded it, and went to build hte directory, and I had problems with the thing just stopping (timing out?) almost immediately after I clicked build. I know it's the code, because I replaced the original code, and then tried building it again, and it worked just fine then.

Help? Ideas? I really wanna have the links randomized (after the new and pop).

------------------

--Sanguinarius
The Real Vampire Directory
www.sanguinarius.org/cgi-bin/links/pages/
Quote Reply
Re: Random Order of Links -- Code In reply to
This worked fine for me. The only change I made was to take out all the extra spaces/tabs before the actual lines of code that got put in through the copy/paste. Perhaps that is why yours is hanging??

It randomizes the order differently on each build which is just what I need. Ideally, I'd like to have the pop and cool links (perhaps even the rated ones) listed first, then the rest in a randomized (different on each build) order ... but this is certainly better than what I had.

Now no one link will forever be buried on the last page of any category.

Thank you!

--Train
Quote Reply
Re: Random Order of Links -- Code In reply to
 
Quote:
It randomizes the order differently on each build which is just what I need. Ideally, I'd like to have the pop and cool links (perhaps even the rated ones) listed first, then the rest in a randomized (different on each build) order ... but this is certainly better than what I had.

Now no one link will forever be buried on the last page of any category.

MOMMY!! I'll go try it again. I'm glad I re-found this thread! Smile Smile Smile Smile

------------------

--Sanguinarius
The Real Vampire Directory
www.sanguinarius.org/cgi-bin/links/pages/
Quote Reply
Re: Random Order of Links -- Code In reply to
Grrr...I try building pages, and it times out (or I assume it's timing out--see below; addendum). So I try the staggered. I go on to step 2, and I get:

Quote:
Building Pages
Step: Rebuilding Category Pages

Pages built on 3-Oct-1999 at 13:34:42
--------------------------------------------------------

Rebuilding Categories 0 -> 19.

** Building Category: Blood ...
Building Category: Blood
Subcategories: 2
Links: 9
Directory: /custs/home/s/san16863/public_html/cgi-bin/links/pages/Blood
Filename : /custs/home/s/san16863/public_html/cgi-bin/links/pages/Blood/index.html

** Done (1 s)!

** Building Category: Blood/Bloodletting_and_Bloodplay ...
Building Category: Blood/Bloodletting_and_Bloodplay
Subcategories: 0
Links: 11
Directory: /custs/home/s/san16863/public_html/cgi-bin/links/pages/Blood/Bloodletting_and_Bloodplay
Filename : /custs/home/s/san16863/public_html/cgi-bin/links/pages/Blood/Bloodletting_and_Bloodplay/index.html
Subpage : /custs/home/s/san16863/public_html/cgi-bin/links/pages/Blood/Bloodletting_and_Bloodplay/more2.html

** Done (1 s)!

** Building Category: Blood/Health_Concerns ...
Building Category: Blood/Health_Concerns
Subcategories: 0
Links: 5
Directory: /custs/home/s/san16863/public_html/cgi-bin/links/pages/Blood/Health_Concerns
Filename : /custs/home/s/san16863/public_html/cgi-bin/links/pages/Blood/Health_Concerns/index.html

** Done (0 s)!

** Building Category: Miscellaneous ...

CGI ERROR
==========================================
Error Message : fatal error: Not an ARRAY reference at nph-build.cgi line 906.

Script Location : nph-build.cgi
Perl Version : 5.00404

Form Variables
-------------------------------------------
auto : 0
staggered : 1
step : 2

Environment Variables
-------------------------------------------
AUTH_TYPE : Basic
CONTENT_LENGTH : 0
DOCUMENT_ROOT : /usr/local/zeus/web_roots/main/www.sanguinarius.org
GATEWAY_INTERFACE : CGI/1.1
HTTP_ACCEPT : */*
HTTP_ACCEPT_ENCODING: gzip, deflate
HTTP_ACCEPT_LANGUAGE: en-us
HTTP_AUTHORIZATION : Basic U2FuZ3VpbmFyaXVzOnNoZWFyc2Ux
HTTP_CONNECTION : Keep-Alive
HTTP_HOST : www.sanguinarius.org
HTTP_REFERER : http://www.sanguinarius.org/cgi-bin/links/admin/nph-build.cgi?staggered=1
HTTP_USER_AGENT : Mozilla/4.0 (compatible; MSIE 5.0; Windows 95; DigExt)
PATH : /usr/bin:/usr/ucb/bin:/usr/local/bin
QUERY_STRING : staggered=1&step=2&auto=0
REMOTE_ADDR : 152.207.25.86
REMOTE_HOST : 152.207.25.86
REMOTE_USER : Sanguinarius
REQUEST_METHOD : GET
REQUEST_URI : /cgi-bin/links/admin/nph-build.cgi?staggered=1&step=2&auto=0
SCRIPT_FILENAME : /usr/local/zeus/web_roots/main/www.sanguinarius.org/cgi-bin/links/admin/nph-build.cgi
SCRIPT_NAME : /cgi-bin/links/admin/nph-build.cgi
SERVER_ADMIN : webmaster@myhost
SERVER_NAME : www.sanguinarius.org
SERVER_PORT : 80
SERVER_PROTOCOL : HTTP/1.1
SERVER_SOFTWARE : Zeus/3.1
TZ : US/Eastern
VSERVER_NAME : main

Why me, oh, Lord? ? Why me? Frown

* Addendum: I assume it's timing out...it just goes so far, to here: "** Building Category: Blood/Health_Concerns ... " and then does nothing else.

------------------

--Sanguinarius
The Real Vampire Directory
www.sanguinarius.org/cgi-bin/links/pages/


[This message has been edited by Sanguinarius (edited October 03, 1999).]
Quote Reply
Re: Random Order of Links -- Code In reply to
  
Hey Alex.. Is it possible to do the same thing with the CATEGORIES also? Correct me if im wrong, but the links are randomized, but the categories that they are listed in are still listed in alphabetical order.. So is there a way to also randomize the CATEGORIES in the search resultd?


Conan
Quote Reply
Re: Random Order of Links -- Code In reply to
It worked for me and I liiiiike it.


------------------
Will
Webmaster
FishHoo! Search index for Fishermen
www.fishhoo.com
Quote Reply
Re: Random Order of Links -- Code In reply to
how does this code work?
does it list the links randomly regardless
or it lists new then cool then random
Quote Reply
Re: Random Order of Links -- Code In reply to
Train,

I don't know if you can have Top rated sites at the head of the listings, but your default should be to have the Cool (Pop) links and New links come to the top, followed by the rest of the gang, sorted whichever way you have things set up, random or alphabetically.

What does your code look like?






[This message has been edited by TrainedMonkey (edited December 13, 1999).]
Quote Reply
Re: Random Order of Links -- Code In reply to
The random code worked good, however, I would like to keep my categories sorted by Title and only randomize my search results.

Anybody with an idea of how I can do this?

Thanks!
Adam
Quote Reply
Re: Random Order of Links -- Code In reply to
Hallo!

I've got the same problem as Sanguinarius explained in this thread changing the sorting routine:
Code:
Error Message : fatal error: Not an ARRAY reference at nph-build.cgi line 906.

Surprisingly I get NO error when I tried it at virtualave.net! (This is my trial-webspace)
So, what can be the problem? And how to solve it? Any suggestions?

Thanks a lot
Stefan

------------------
visit Juhu!Katzen!
http://www.juhukatzen.de/