Gossamer Forum
Quote Reply
ispop
Hi,
I just wanted to be able to sort the links so the popular links are always on top, I thought if I swiched all the "isnew"s to "ispop"s in the "sub build_sorthit" part it would work, but I was wrong. Below is what I tried.

Thanks for any help




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, %ispop, %iscool, $hit, $i, @sorted);

for ($i = 0; $i < $num; $i++) {
$sortby{$i} = $unsorted[$db_sort_links + ($i * ($#db_cols+1))];
($unsorted[$db_ispop + ($i * ($#db_cols+1))] eq "Yes") and ($ispop{$i} = 1);
($unsorted[$db_isnew + ($i * ($#db_cols+1))] eq "Yes") and ($iscool{$i} = 1);
}
foreach $hit (sort {
($isnew{$b} and !$ispop{$a}) and return 1;
($isnew{$a} and !$ispop{$b}) and return -1;
($iscool{$b} and !$iscool{$a}) and return 1;
($iscool{$a} and !$iscool{$b}) and return -1;
($isnew{$a} and $ispop{$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;
}


Quote Reply
Re: ispop In reply to
I don't know if it would work or not, but you didn't replace all of the '$innew' instances... there are 3 that I see on the left in the lower section.

I would change them over and retry it...

Matt


Matthew March
1-On-1 Free Basketball Game
http://basketball-game.com/