Icy Phoenix

     
 

Mysql Query With Rank

Mysql Query With Rank

Article
Reply with quote    Download Post  
Post 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...



 
KugeLSichA - View user's profile Send private message  
KugeLSichA [ Fri 01 Apr, 2011 23:22 ]
Icy Phoenix is an open source project, you can show your appreciation and support future development by donating to the project.

Support us


Mysql Query With Rank

Comments
Reply with quote    Download Post  
Post Re: Mysql Query With Rank 
 
Code: [Download] [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: [Download] [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. }  




 
Informpro - View user's profile Send private message  
Informpro [ Sat 02 Apr, 2011 01:14 ]
Reply with quote    Download Post  
Post 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



 
Last edited by KugeLSichA on Sun 03 Apr, 2011 16:22; edited 1 time in total 
KugeLSichA - View user's profile Send private message  
KugeLSichA [ Sun 03 Apr, 2011 16:13 ]
Reply with quote    Download Post  
Post Re: Mysql Query With Rank 
 
(use code syntax=php !)
For the group query, use something like
Code: [Download] [Hide]
  1. AND g.group_id NOT IN (1, 2, 3, 4, 5, 43) 
Much more readable than
Code: [Download] [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 ;-).



 
Informpro - View user's profile Send private message  
Informpro [ Sun 03 Apr, 2011 16:17 ]
Reply with quote    Download Post  
Post Re: Mysql Query With Rank 
 
Ok thanks



 
KugeLSichA - View user's profile Send private message  
KugeLSichA [ Sun 03 Apr, 2011 16:23 ]
Display posts from previous:    

HideWas this topic useful?

This forum is locked: you cannot post, reply or edit topics.  This topic is locked: you cannot edit posts or make replies.  Page 1 of 1
 
 




 


 

  cron