Jump to content

SQL query


Kingy

Recommended Posts

I am trying to make a statistic on my irc for the person that shouts the most (ie. the user that users the most uppercase letters). What i am trying to do is select info from the mysql database with two coloums (letters, shout). Letters represents the amount of letters the user has typed, shout represents the amount of uppercase letters the user typed.

Simple enough to make a percentage of this and display it, but im confused

 

$result = mysql_query("SELECT * FROM stats ORDER BY letters, shout DESC LIMIT 1");
while($row = mysql_fetch_array( $result )) {
  $letters = $row['letters'];
  $shout = $row['shout'];
  $user = $row['user'];
  $percent = (($letters/$shout)*100);
  $percent = round($percent ,2);
  fputs($conn,"PRIVMSG $room The top shouter on the network is $user with a shout percentage of $percent% \r\n");
       }       

 

this doesn't return the right amount. Any ideas? If any help could be given to the next bit as well, i will eventually add to this to maybe show the 2nd user on  this list or even the user with the lowest percentage? thanks

Link to comment
Share on other sites

I mean it doesn't show the person with the highest percent

 

heres apart of the table

 

id user letters shout

1 user1  1000  100

2 user2  500    300

 

so with the sql query i would want it to show that user2 has the highest percentage of shouting

 

but with that query above it doesn't display the right user. What im asking is, does that query look right or not?

Link to comment
Share on other sites

ok there is a problem now, this script doesn't show the user with the top percentage, it shows the user with the top shout characters, so the script is working fine, but displaying the wrong user because it show the user with top Shout not top percentage

Link to comment
Share on other sites

Ok that there works perfectly now, thanks for that one..

 

My next question for this query is how do i display 2 people but with different wording,

 

eg: in the while look ive put

 

while (...) {

echo "The top shouter on the network is $user with $percent%";

}

 

But if i put in the sql query LIMIT 2, im going to get the that echo two times.

 

What i would like to do is echo something like this...

 

The top shouter on the network is $user with $percent%

Another person that shouts is $user2 with $percent2%

 

or something along those lines??

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.