Mysql Query With Rank »  Show posts from    to     

Icy Phoenix


Archived phpBB Topics (Styles, Mods, Support) - Mysql Query With Rank



KugeLSichA [ Fri 01 Apr, 2011 23:22 ]
Post subject: Mysql Query With Rank
Hey guys...

Yeah its me again

Another thing i need to figure out...

the DB structure is with id, user_id, score,

i have a user_id and a score (number)... and i want to count the entries from the DB... order by score and gives back the Rank/place/count if the user_id matches...

for example:

id=1 user_id=2 score=50 <--------- 1. place
id=2 user_id=3 score=23 <--------- 3. place
id=3 user_id=7 score=34 <--------- 2. place

i hope you can understand what i mean, and help me with that... thanks...


Informpro [ Sat 02 Apr, 2011 01:14 ]
Post subject: Re: Mysql Query With Rank
Code: [Hide]
  1. SELECT user_id, username, user_rank, user_rank2, user_rank3 ... 
  2. FROM USERS_TABLE 
  3. ORDER BY score DESC 
The PHP code should'nt be too difficult ;-). Something like
Code: [Hide]
  1. <?php $result = $db->sql_result($sql);
  2. $place = 0;
  3. while ($row = $db->sql_fetchrow($result))
  4. {
  5. echo 'Hi I\' ' . $row['username'] . ', id ' . $row['user_id'] . '. My place is ' . ++$place . ', and my first rank is ' . $row['user_rank'] . '<br />'; //feel free to display more ranks
  6. }


KugeLSichA [ Sun 03 Apr, 2011 16:13 ]
Post subject: Re: Mysql Query With Rank
Thanks Informpro,

you point me in the right direction

I´ve done it like this... maybe you can take a look.. the code works well, but maybe its not perfect.. let me know if i can tweak it a bit

Spoiler: [ Show ]


Its for a User Dynamic Signature with data based from Users Profile & Course Handicap site for our Golf MMoG...

herzscheisse


Informpro [ Sun 03 Apr, 2011 16:17 ]
Post subject: Re: Mysql Query With Rank
(use code syntax=php !)
For the group query, use something like
Code: [Hide]
  1. AND g.group_id NOT IN (1, 2, 3, 4, 5, 43) 
Much more readable than
Code: [Hide]
  1. AND g.group_id <> 1 
  2. AND g.group_id <> 2 
  3. AND g.group_id <> 3 
  4. AND g.group_id <> 4 
  5. AND g.group_id <> 5 
  6. AND g.group_id <> 43 
For everything else, it looks good. Nice job ;-).


KugeLSichA [ Sun 03 Apr, 2011 16:23 ]
Post subject: Re: Mysql Query With Rank
Ok thanks




Powered by Icy Phoenix