PDA

View Full Version : mysql to select highest users's post count?


postalbobo
Thu 23rd Aug '01, 3:00pm
I want to find the highest user post count to aid in an average for a script I'm working on, what would the sql query for that be?

SELECT posts from user where posts > 0 ORDER BY posts DESC LIMIT 0, 1 ?

postalbobo
Thu 23rd Aug '01, 3:08pm
answered my own question.

Chen
Thu 23rd Aug '01, 3:14pm
SELECT posts FROM user ORDER BY posts DESC LIMIT 1
:)

postalbobo
Thu 23rd Aug '01, 3:18pm
Ok next question:

How do I code in the equivalent of this in php:

255 = ( ( $highestpostcount / 255 ) * X )

I need to find X to use it as a multiplier variable for the rest of the glowy color script I'm using, so that the brightest color will always be a postcount equal to the top poster's.

Chen
Thu 23rd Aug '01, 3:24pm
I really don't understand what you are trying to do man. Can you be any more specific? :)

postalbobo
Thu 23rd Aug '01, 3:29pm
I'm trying to set up a multiplier so that in my glowy color script (http://www.dirgotronix.net/test/glow.phps) it will poll the database for the highest post count (which atm is 1206), the post count of the #1 top postiing user.

like I said, I need to find X for:

255 = ( ( $highestpostcount / 255 ) * X )
where $highestpostcount = 1206, but will change, of course.

Then, I use X like so:

X is set as $colormultiplier
for each color (r,g,b) I run the following:
// Red
if ( $r > 15 )
{
$r1 = $glowposts / 255;
$r1 = round($r1);
$r1 = ( $r1 * $colormultiplier );
$rr = dechex($r1);
}
else
{
$rr = "0" . dechex($r1);
}
where $r is the red value of the users favorite color, $glowposts is their post count. This means that people's usernames will glow brighter the more posts they have, and the top posts's glow will for example (for white) be FFFFFF as long as they are the top poster. If the top poster had 255 posts, the $colormultiplier would have to be set as 255, and go progressively lower as their post count grew.

Chen
Thu 23rd Aug '01, 3:42pm
I think this will do it:
$colormultiplier = "65025 / $highestpostcount";

postalbobo
Thu 23rd Aug '01, 3:43pm
how did you get 65025?

postalbobo
Thu 23rd Aug '01, 3:46pm
duh

postalbobo
Thu 23rd Aug '01, 4:40pm
Ok, I'm finding that my math is all wrong here... I'm not getting things the right way. Have a look at the src:

http://www.dirgotronix.net/test/glow.phps
and the script in action:

http://www.dirgotronix.net/test/glow.php?glowposts=1103&glowusername=Jason&glowuserid=1

looks like:

1206 = top posts
54 = multiplier
purple = fav color
1 = userid
Jason = username
800080 = fav color in hex
128 0 128 = fav color in dec
108 108 = adjusted color in dec
6c006c = adjusted color in hex
Jason - final output.

yet, at 1206 posts, mine would be much brighter than my fav color (red is 162 where my fav is 128, etc)

I'm lost...

postalbobo
Thu 23rd Aug '01, 5:31pm
Fixed! If you want, reload the source page and replace it. Now it works according to their post count in relation to the max post count. Wheee!

Gellpak
Mon 27th Aug '01, 10:59am
yknow you could always just select MAX from the table....