Gossamer Forum
Home : Products : Links 2.0 : Customization :

Sort by Average Daily Hits

Quote Reply
Sort by Average Daily Hits
The following modification of the db.cgi build_sorthit subroutine will sort listings by hits in descending order from highest to lowest based on average daily hits.

This answered 2 questions I posted earlier and were answered by Alex - thanks!

I post this so that anyone else wanting something similar can find it here. No reply necessary.

Code:
sub build_sorthit {


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

for ($i = 0; $i < $num; $i++) {
$days_old = int &days_old ($unsorted[$db_modified + ($i * ($#db_cols+1))]) | | 1;
$sortby{$i} = $unsorted[$db_sort_links + ($i * ($#db_cols+1))] / $days_old;
}
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;
}

Dan Smile


[This message has been edited by dan (edited February 10, 1999).]

[This message has been edited by dan (edited February 10, 1999).]
Quote Reply
Re: Sort by Average Daily Hits In reply to
Just make sure if you use this, that you remove the space between the pipes '|'. UBB has the nasty habit of changing double pipes to pipe space pipe.

Cheers,

Alex
Quote Reply
Re: Sort by Average Daily Hits In reply to
And how would you ONLY sort alphabetically?