0

I have 4 columns: value_id, customer_id, name, and score

Now I have the customer_id and I want to get the rank by sorting the score values in DESC order

This is the MySQL command I have in my page

http://livetut.com/game/riddlehunt/score/list.php?start=0

$query2=" SELECT * FROM ridd ORDER BY score DESC ";
$count=$dbo->prepare($query2);
$count->execute();
$nume=$count->rowCount();

I want to get your rank from the customer_id which is unique for every user

I do not want to use the select statement again can i add some thing to the $query2 to get the value

1 Answers1

0

I think you may find your answer here : how to get position rank of specific row using just mysql query?

It seem's to be the same problem,

Here is the answer of the link above, if that can help you :

SELECT users1.id, (users1.points+users1.extra_points) AS total, COUNT(*)+1 AS rank
FROM users users1
INNER JOIN users users2 ON users1.points+users1.extra_points < users2.points+users2.extra_points
WHERE users1.id = $id

Good luck.

Community
  • 1
  • 1
Peter
  • 1,719
  • 4
  • 22
  • 31
  • i do not want to use the select statement again can i add some thing to the $query to get the value – Venkat Eswaran Jun 17 '14 at 20:51
  • You can do query in the same query you had at the beginning. Like: SELECT ///*.ridd, users1.id, (users1.points+users1.extra_points) AS total, COUNT(*)+1 AS rank FROM ridd [INNERJOIN HERE] ORDER BY score DESC – Peter Jun 18 '14 at 14:19