Gossamer Forum
Home : General : Perl Programming :

prioritizing records...

Quote Reply
prioritizing records...
I'm trying to write an ad management script in Perl and mySQL. I've figured out how to grab a random record, and how to limit the resulting record to a specified priority. However, I'd really like to be able to set priorities (1 to 10, 10 highest) based on per click payout automaticly upon updating the database.

I know that I need to do something with the low and high value and average them somehow into something usefull, but I've been at a loss for coming up with a working algorithm.

Any tips would be very helpful and appreciated Smile

--Philip
Links 2.0 moderator
Quote Reply
Re: [ThatPerson1024] prioritizing records... In reply to
I think I got it...

1) I got the highest payout
Code:
select max(payout) from sites
2) got the total number of records
Code:
select count(*) from sites
3) divided max value by number of records
Code:
$tenth = sprintf ("%.3f", ( $max / $num));
4) made a hash of priorities to payout values
Code:
($priority{$_} = $tenth * $_) for (1 .. 10);
5) made a loop and executed update statements...
Code:
"update sites set priority = $_ where payout > " . ($priority{$_} - $tenth) . " and payout < " . ($priority{$_} + $tenth)



--Philip
Links 2.0 moderator

Last edited by:

ThatPerson1024: Jan 9, 2002, 12:41 AM