Gossamer Forum
Home : Products : Links 2.0 : Customization :

Sort By Rating

Quote Reply
Sort By Rating
I want my links sorted in the following order.
1. New Links first
2. Highest Rated Links
3. Cool Links
4. The rest alphabetically.
Could someone please tell me why the code below doesn't work. It just sorts it by new, cool and then alphabetical. Thanks


#
my (@unsorted) = @_;
my ($num) = ($#unsorted+1) / ($#db_cols+1);
my (%sortby, %isnew, %rating, %iscool, $hit, $i, @sorted);
# 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;
($rating{$b} and !$rating{$a}) and return 1;
($rating{$a} and !$rating{$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;
}

sub urlencode {

Subject Author Views Date
Thread Sort By Rating ukie69 1282 Oct 17, 2000, 2:55 PM
Thread Re: Sort By Rating
Stealth 1258 Oct 17, 2000, 7:44 PM
Thread Re: Sort By Rating
ukie69 1247 Oct 18, 2000, 7:15 AM
Thread Re: Sort By Rating
Stealth 1247 Oct 18, 2000, 8:52 AM
Thread Re: Sort By Rating
ukie69 1241 Oct 18, 2000, 9:37 AM
Post Re: Sort By Rating
ukie69 1239 Oct 18, 2000, 9:39 AM