Gossamer Forum
Home : Products : Links 2.0 : Discussions :

sort links by rating

Quote Reply
sort links by rating
I want to sort my links by rating so I changed
$db_sort_links to 11
But it's sorting from 1 to 10 now and of course I want the links with the best rating on top. Can somebody tell me how to do this?

Quote Reply
Re: sort links by rating In reply to
Code:
sub build_sorthit {
# --------------------------------------------------------
# This function sorts a list of links. It has been modified to sort
# new links first, then cool links, then the rest alphabetically. By modifying
# the sort function below, you can sort the links however you like (by date,
# or random, etc.).
#
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;
if ($db_sort{$db_cols[$db_sort_links]} eq "date") {
($isnew{$a} and $isnew{$b}) and return &date_to_unix($sortby{$b}) <=> &date_to_unix($sortby{$a});
($iscool{$a} and $iscool{$b}) and return &date_to_unix($sortby{$b}) <=> &date_to_unix($sortby{$a});
return $sortby{&date_to_unix($b)} <=> $sortby{&date_to_unix($a)};
}
elsif ($db_sort{$db_cols[$db_sort_links]} eq "numer") {
($isnew{$a} and $isnew{$b}) and return $sortby{$b} <=> $sortby{$a};
($iscool{$a} and $iscool{$b}) and return $sortby{$b} <=> $sortby{$a};
return $sortby{$b} <=> $sortby{$a};
}
else {
($isnew{$a} and $isnew{$b}) and return $sortby{$a} cmp $sortby{$b};
($iscool{$a} and $iscool{$b}) and return $sortby{$a} cmp $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;
}
Jerry Su
Quote Reply
Re: [jsu] sort links by rating In reply to
Hallo,
this lock like perfeckt (;-))

But in witch Datei i have to modyfie this Part?

I cant find the right Place in nph-build.cgi

Thank you verry mutch fore your Help.
Mutch Greatings
Manfred
Quote Reply
Re: [ManfredG] sort links by rating In reply to
look in db_utils.pl


Leonard
aka PerlFlunkie
Quote Reply
Re: [PerlFlunkie] sort links by rating In reply to
Hallo Leonard,
thank you verry mutch fore your Help.

I was trie this now, but the surting is allways by
NEW COOL Alphabet
and not by

NEW COOL RATING

What are you thinking,
what can be the Problem?

Mitch Greatings
Manfred
Quote Reply
Re: [ManfredG] sort links by rating In reply to
You installed the mod as shown above? Did you re-build (build all or build staggered) your pages?


Leonard
aka PerlFlunkie
Quote Reply
Re: [PerlFlunkie] sort links by rating In reply to
Hallo Leonard,
thank you verry mutch vore your Help.

I was triing like above but it is not working.
I was trie with:
Building
Build All
Staggered
Staggered (Auto)

But there is no diference.

I am using Links 2.0 with Templates.

What can i doo?

Mutch Greatings
Manfred
Quote Reply
Re: [ManfredG] sort links by rating In reply to
I did not a find a definite answer, but here a few things to look at/try:

http://www.gossamer-threads.com/...cgi?post=89846#89846

http://www.gossamer-threads.com/...cgi?post=50288#50288

http://www.gossamer-threads.com/...cgi?post=92182#92182


Leonard
aka PerlFlunkie