Re: auto incrementing rows from query..

From: Date: Wed, 06 Dec 2000 08:09:55 +0000
Subject: Re: auto incrementing rows from query..
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-5038@lists.php.net to get a copy of this message
Greetings, Chad! At 06.12.2000, 11:00, you wrote: CD> I'm trying to determine the percentile value of where a row lies in a CD> query.. hard to explain, but I'll try. CD> I do a select all of my table, sorting it by SCORE. I want to find the CD> position of a certain row in that select all, get that row #, and then I can CD> calculate the percentile fine by dividing that position into the total # of CD> rows, then multiplying by 100. CD> my code is like: CD> $querysetup = "SELECT SCORE, PID from pictures where VOTES > 100 order by CD> SCORE DESC"; Ugh. I don't think that I quite get you, but: If you want to find "that row" by SCORE, then you should issue something like SELECT COUNT(*) FROM pictures WHERE VOTES>100 AND SCORE>$your_needed_SCORE If you want to find "that row" by PID, then SELECT COUNT(*) FROM pictures WHERE VOTES>100 AND SCORE>(SELECT SCORE FROM pictures WHERE PID=$your_needed_PID) Thus you get the number of rows before "that row" Then issue SELECT COUNT(*) FROM pictures WHERE VOTES>100 to get _total_ number of rows then divide one by the other, multiply by 100 and you're all done. :] I'm almost sure that can be done in a more elegant way, though... -- Yours, Alexey V. Borzov, Webmaster of RDW

« previous php.db (#5038) next »