Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sorting and pulling scores from database

I'm developing a sort of game site where every members score is saved for each day. Now I have a database with a table for user information and a table for user score. The user_score table contains:

ID | User_ID | Points | Day

Every day the user gets their graph updated in their personal part of the homepage. The graph shows the users score for each day, with a yAxes displaying the highest score in the top of the graph. I need to emphasis that the graph displays the users own score only, like a form curve for that specific user.

My issue is that I want to display the users position in the ranking system in the graph, not their score...

So my question would be: What do I change in order to give the user his positions not the score? I was trying to add another table in the database to sort this out, but it seems like a pickle.

Should I add another table, should I do anything special in my query? Im using Google Chart API, and trying to follow another thread to make the PHP connection

like image 551
Bebop Avatar asked Dec 13 '25 16:12

Bebop


1 Answers

Simply use this..

 $sql=mysql_query("select * from `user_score` order by Points desc");
 // Store the user Id in $userid variable of the user whose position you want to show
 $position=0;
 while($row=mysql_fetch_array($sql))
 {
    $position+=1;
    if($row['User_ID']==$userid)
       break;
 }

 echo $position; // here you got the position of that user.
like image 128
Tapas Pal Avatar answered Dec 15 '25 04:12

Tapas Pal