I have read the archives on this subject and it was pretty confusing on how to do this and make it work. So I figured I would update the thread. I would like the links to be listed randomly rather then alphabetically (keeping the new and popular links first) within each category. Any info on how to do this would be appreciated (keeping in mind my limited capabilities). Keith
Jan 22, 1999, 10:29 AM
Enthusiast (760 posts)
Jan 22, 1999, 10:29 AM
Post #2 of 17
Views: 5059
Step 1:
=======
Change variable $db_sort_links in [links.def] file to equal 8 - $db_sort_links = 8;
---------------------------------------------
Step 2:
=======
Change build_sorthit subroutine in [db.cgi] script to:
sub build_sorthit {
my (@unsorted) = @_;
my ($num) = ($#unsorted+1) / ($#db_cols+1);
my (%sortby, $hit, $i, @sorted);
for ($i = 0; $i < $num; $i++) {
$sortby{$i} = $unsorted[$db_hits + ($i * ($#db_cols+1))];
}
foreach $hit (sort { return $sortby{$b} <=> $sortby{$a} } (keys %sortby)) {
$first = ($hit * $#db_cols) + $hit;
$last = ($hit * $#db_cols) + $#db_cols + $hit;
push (@sorted, @unsorted[$first .. $last]);
}
return @sorted;
}
---------------------------------------------
That should do it.
Dan
=======
Change variable $db_sort_links in [links.def] file to equal 8 - $db_sort_links = 8;
---------------------------------------------
Step 2:
=======
Change build_sorthit subroutine in [db.cgi] script to:
sub build_sorthit {
my (@unsorted) = @_;
my ($num) = ($#unsorted+1) / ($#db_cols+1);
my (%sortby, $hit, $i, @sorted);
for ($i = 0; $i < $num; $i++) {
$sortby{$i} = $unsorted[$db_hits + ($i * ($#db_cols+1))];
}
foreach $hit (sort { return $sortby{$b} <=> $sortby{$a} } (keys %sortby)) {
$first = ($hit * $#db_cols) + $hit;
$last = ($hit * $#db_cols) + $#db_cols + $hit;
push (@sorted, @unsorted[$first .. $last]);
}
return @sorted;
}
---------------------------------------------
That should do it.
Dan
Jan 23, 1999, 11:22 AM
Enthusiast (760 posts)
Jan 23, 1999, 11:22 AM
Post #5 of 17
Views: 5060
Hi:
I may have misunderstood you. Are you looking for a random or non-random sorting - or a combination thereof?
It seems you want new sites first followed by the remaining sites in order of popularity. Is this right? If so then this is not random. Further, then unless new sites are added and/or relative popularity of sites changes, the order will remain the same when the database is re-indexed (i.e., updated).
If the case then to place new sites first followed by a numerical sort (on the hits field) of non-new sites is a bit involved. It may require two juxtaposed sorts - the first sorts on time in the database and the other sorts numerically using the code I supplied but excluding new sites (and appends the original sorted array). Perhaps Alex can shed some light.
Dan
I may have misunderstood you. Are you looking for a random or non-random sorting - or a combination thereof?
It seems you want new sites first followed by the remaining sites in order of popularity. Is this right? If so then this is not random. Further, then unless new sites are added and/or relative popularity of sites changes, the order will remain the same when the database is re-indexed (i.e., updated).
If the case then to place new sites first followed by a numerical sort (on the hits field) of non-new sites is a bit involved. It may require two juxtaposed sorts - the first sorts on time in the database and the other sorts numerically using the code I supplied but excluding new sites (and appends the original sorted array). Perhaps Alex can shed some light.
Dan
Jan 24, 1999, 3:18 PM
Novice (44 posts)
Jan 24, 1999, 3:18 PM
Post #8 of 17
Views: 5052
Whoa, I did find this from Alex in June:
Here's a new mod that will make the popular and new links displayed before any others.
In db.pl, replace build_sorthit with:
<PRE>
sub build_sorthit {
# --------------------------------------------------------
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 ($ispop{$i} = 1);
}
foreach $hit (sort {
if ($ispop{$b} and !$ispop{$a}) { return 1; }
if ($ispop{$a} and !$ispop{$b}) { return -1; }
if ($isnew{$b} and !$isnew{$a}) { return 1; }
if ($isnew{$a} and !$isnew{$b}) { return -1; }
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;
}
</PRE>
However, I can't get it to work. If I include the <PRE> tags (what are those for) the program bombs out. Without them the pages are built but they are not randomized with each build.
Keith
Here's a new mod that will make the popular and new links displayed before any others.
In db.pl, replace build_sorthit with:
<PRE>
sub build_sorthit {
# --------------------------------------------------------
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 ($ispop{$i} = 1);
}
foreach $hit (sort {
if ($ispop{$b} and !$ispop{$a}) { return 1; }
if ($ispop{$a} and !$ispop{$b}) { return -1; }
if ($isnew{$b} and !$isnew{$a}) { return 1; }
if ($isnew{$a} and !$isnew{$b}) { return -1; }
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;
}
</PRE>
However, I can't get it to work. If I include the <PRE> tags (what are those for) the program bombs out. Without them the pages are built but they are not randomized with each build.
Keith
Feb 7, 1999, 4:26 AM
Novice (35 posts)
Feb 7, 1999, 4:26 AM
Post #9 of 17
Views: 5055
I have been wrestling with the same thing and to follow is what I have finnaly gotten.
I wanted to list my new links first followed by popular links followed by a random listing of links.
Change variable $db_sort_links in [links.def] file to equal 8 - $db_sort_links = 8;
in the db.pl
sub build_sorthit {
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; }
}
foreach $hit (sort {
if ($isnew{$b} and !$isnew{$a}) { return 1; }
if ($isnew{$a} and !$isnew{$b}) { return -1; }
if ($iscool{$b} and !$iscool{$a}) { return 1; }
if ($iscool{$a} and !$iscool{$b}) { return -1; }
if ($isnew{$a} and $isnew{$b}) { return lc($sortby{$a}) cmp lc($sortby{$b}); }
if ($iscool{$a} and $iscool{$b}) { 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;
}
__________________________________
There may be a better way but this is what I have figured out.
------------------
Thanks for all the help.
I wanted to list my new links first followed by popular links followed by a random listing of links.
Change variable $db_sort_links in [links.def] file to equal 8 - $db_sort_links = 8;
in the db.pl
sub build_sorthit {
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; }
}
foreach $hit (sort {
if ($isnew{$b} and !$isnew{$a}) { return 1; }
if ($isnew{$a} and !$isnew{$b}) { return -1; }
if ($iscool{$b} and !$iscool{$a}) { return 1; }
if ($iscool{$a} and !$iscool{$b}) { return -1; }
if ($isnew{$a} and $isnew{$b}) { return lc($sortby{$a}) cmp lc($sortby{$b}); }
if ($iscool{$a} and $iscool{$b}) { 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;
}
__________________________________
There may be a better way but this is what I have figured out.
------------------
Thanks for all the help.
Sep 1, 1999, 12:12 AM
User (155 posts)
Sep 1, 1999, 12:12 AM
Post #10 of 17
Views: 5056
Hello,
Is there a way to just randomize the order in which the links are displayed in each category each time the directory is rebuilt?
I've had webmasters complain to me that their site never gets visted because they are on like, page more6.html -- they are good sites, but nobody GOES that far when they search.
------------------
--Sanguinarius
The Real Vampire Directory
www.sanguinarius.org/cgi-bin/links/pages/
Is there a way to just randomize the order in which the links are displayed in each category each time the directory is rebuilt?
I've had webmasters complain to me that their site never gets visted because they are on like, page more6.html -- they are good sites, but nobody GOES that far when they search.
------------------
--Sanguinarius
The Real Vampire Directory
www.sanguinarius.org/cgi-bin/links/pages/
Sep 8, 1999, 7:14 AM
User (155 posts)
Sep 8, 1999, 7:14 AM
Post #14 of 17
Views: 5062
Quote:
I have been wrestling with the same thing and to follow is what I have finnaly gotten. I wanted to list my new links first followed by popular links followed by a random listing of links.
Change variable $db_sort_links in [links.def] file to equal 8 - $db_sort_links = 8;
That will sort the links by HITS won't it, not random order? Someone, I'm confused here. :/
------------------
--Sanguinarius
The Real Vampire Directory
www.sanguinarius.org/cgi-bin/links/pages/
Sep 8, 1999, 7:26 AM
User (155 posts)
Sep 8, 1999, 7:26 AM
Post #15 of 17
Views: 5054
If there is a mod that will post the links by the following order: new, popular, random order (changing order every time pages are rebuilt), shouldn't it get posted in the Resource center?
------------------
--Sanguinarius
The Real Vampire Directory
www.sanguinarius.org/cgi-bin/links/pages/
------------------
--Sanguinarius
The Real Vampire Directory
www.sanguinarius.org/cgi-bin/links/pages/
Oct 3, 1999, 5:30 AM
User (155 posts)
Oct 3, 1999, 5:30 AM
Post #16 of 17
Views: 5053
Still no help? Well, guess what? I'm still wanting to do this. Can anyone tell me once and for all, definitively, what to do in order to:
put new first followed by pop followed by random links (in a different random order each time I rebuild the page)?
*waves money around* I'm getting desperate...
Please, I don't know if the above mod in the post above is a random sorting with each build.
------------------
--Sanguinarius
The Real Vampire Directory
www.sanguinarius.org/cgi-bin/links/pages/
put new first followed by pop followed by random links (in a different random order each time I rebuild the page)?
*waves money around* I'm getting desperate...
Please, I don't know if the above mod in the post above is a random sorting with each build.
------------------
--Sanguinarius
The Real Vampire Directory
www.sanguinarius.org/cgi-bin/links/pages/