|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||||
|
|||||
|
detecting duplicate values and stalling $rank counter?
Spreadsheets like Excel do a nice job of detecting if there are duplicate values with their rank function - this is what I would like to mimic.
This is my small script that detects the rank position of a variable Hank_Wins in a mysql database: php Code:
which, if you spit out the whole array, for Name Hank_Wins and $rank not just Robert's rank on Hank_Wins you would get something like (formatted better): +-------------+-------+------+ | Name | Wins| rank | +-------------+-------+------+ | Jamie | 10 | 14| | Eric | 9 | 13 | | Deryk | 7 | 12 | | Mark | 7 | 11 | | Matthew | 7 | 10 | | Neil | 7 | 9 | | Robert | 6 | 8 | | Douglas | 5 | 7| | Steven | 4 | 6 | | Timothy | 4 | 5 | | Christopher | 3 | 4 | | Dana | 3 | 3 | | George | 2 | 2 | | James | 1 | 1 | +-------------+-------+------+ Notice Deryk, Mark, Matthew and Neil for example all have 7 wins -but the $rank variables has incremented regardless (too bad for Neil especially) I want to be able to detect this and stop my $rank variable from incrementing if there is a duplicate elsewhere in the list - such that these 4 guys would all get the rank of 12, yet Robert would still get 8 MY BASIC ALGORITHIM? Thus in the final version will involve the following: 1) $rank will not be a mutually exclusive list of numbers - duplicates should occur where appropriate, as in the example above. 2) Since Hank_Wins is already sorted in the Select statment, some of the work is already done - I just need to compare the "current"($current) value of $var["Hank_Wins"] with the "previous"($previous) value of $var["Hank_Wins"] as the script moves down the [i]while[i/] loop 3) if $current == $previous then the rank incrementer $rank has to be frozen somehow? 4) once $current does not equal (don't know this syntax) $previous then $rank gets incremented as $rank++ Close? Okay now, how? - I can't quite get it...how compare values in a while loop? how to freeze the $rank counter for each duplicate "pass"? |
|
#2
|
|||||
|
|||||
|
RE: detecting duplicate values and stalling $rank counter?
This may work better
php Code:
|
|
#3
|
|||
|
|||
|
RE: detecting duplicate values and stalling $rank counter?
hmmm still not detecting duplicates...
output as follows, if I echo all 14 ranks: 8 14 5 7 9 10 3 6 11 4 13 12 1 2 I see what you are trying to do, I will work with it, if you have further ideas, much appreciated. |
|
#4
|
|||||||||||
|
|||||||||||
|
RE: detecting duplicate values and stalling $rank counter?
Got it working but one other question...
CHANGED CODE Just had to change one variable in this expression from above: php Code:
should read: php Code:
THE OUTPUT 6 9 4 5 7 7 3 4 7 3 8 7 1 2 (ordered by surname, so does not look as above) Which is not exactly what I expected but will be more useful to me in the end since I am using these ranks as weights - this will provide a narrower band of output values - see next. OUTSTANDING QUESTION: Excel actually ranks but picking up where it left off after duplicates. Thus the start rank in the example above would be 14 and the end rank would be 1 - but with duplicates. Thus, if there were duplicates at rank 12 for 3 people it would read 14, 13, 12, 12 ,12, 9, 8,..., 1 I tried implementing this by simply inserting rank++; as follows: php Code:
To increment despite having a duplicate, but this produces the error: Parse error: parse error, unexpected T_ELSE How would I increment the $rank counter inside the if before the else - or is this just not possible? |
|
#5
|
|||
|
|||
|
RE: detecting duplicate values and stalling $rank counter?
What I have listed above is not right, but the attachment at this thread
http://forums.devshed.com/showthrea...0683#post160683 DOES work properly - see there for what it does. thanks greggory, got me on the right track. |
![]() |
| Viewing: Codewalkers Forums > PHP Related > PHP Coding > detecting duplicate values and stalling $rank counter? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|
|
|