Re: SQL Query Question

From: Date: Sun, 09 Dec 2001 03:24:05 +0000
Subject: Re: SQL Query Question
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-77139@lists.php.net to get a copy of this message
Assuming you have the variable member_id (for the member in question)... Get the score for that member and store it to $score... "SELECT score FROM members WHERE id=$member_id" Then to determine rank, just do this... SELECT COUNT(*)+1 as rank FROM members WHERE SCORE>$score; -Jason Garber IonZoft.com At 08:47 PM 12/8/2001 +0000, Andrew Brampton wrote:
Hi, This isn't a php question, more of a SQL question, but I don't know any where better to send it, and I guess its trival enough for someone here to answer. Anyway, I have a list of members each with a score field. How can I say that Member 3 is ranked 10 out of 100 members for example. Here is the layout of the members table: ID, Name, Score I can get the total count of members in the table, but I don't know how to determine what rank they are, unless I return all the rows in the table (sorted), and cycle through them until I find the member I want, counting how many people are above him... This method would work, but would be slow (and wastful), is there a better way to determine his position with a SQL Query? Thanks in advance Andrew P.S If it matters I'm using MySQL & PHP 4.0.6 on WinXP under Apache 1.3.22


« previous php.general (#77139) next »