Search the Community
Showing results for tags 'rank'.
-
i'am trying to get the users rank so i can display their rank in a div.. i.e you are 30 out of 400 users at getting sales. So far i ve managed to get the order of the users but thats it: i count the date_mades as sales made to get the totals. SELECT usr_id, count(date_made) as dater, @curRank := @curRank + 1 AS rank FROM firsts group BY usr_id order by dater desc gives me : usr_id dater rank 1 20 NULL 16 3 NULL 3 2 NULL 5 1 NULL 9 1 NULL 22 1 NULL 25 1 NULL i found this answer (Attached snippet) but i just get red crosses all over the statement when i try and run it: does anyone else get errors just pasting this into their phpmyadmin? is it a parser problem or syntax? SELECT pid, name, age, rank FROM (SELECT pid, name, age, @curRank := IF(@prevRank = age, @curRank, @incRank) AS rank, @incRank := @incRank + 1, @prevRank := age FROM players p, ( SELECT @curRank :=0, @prevRank := NULL, @incRank := 1 ) r ORDER BY age) s
-
I am writing a golf league management system and one request is to give points for lowest net score. Simple enough. Now when there is a tie I need to go back starting at the first hole and get the lowest score and if a tie move to the next hole and so on. Also there can be more than one division so I have the division seperated. Here is the array containing the players that have tied. In the example below A is the division the next is the Players unique id and ppoints is what they would have gotten if there was no tie. Not all this information is needed but have it in the array until the script is complete. The s_id is needed to update the database which has already been populated with the scores. Array ( [A] => Array ( [193] => Array ( [s_id] => 9 [pid] => 193 [ppoints] => 6 [net] => 31 [tie] => yes ) [199] => Array ( [s_id] => 10 [pid] => 199 [ppoints] => 7 [net] => 31 [tie] => yes ) [191] => Array ( [s_id] => 5 [pid] => 191 [ppoints] => 5 [net] => 31 [tie] => yes ) ) [B] => Array ( [202] => Array ( [s_id] => 8 [pid] => 202 [ppoints] => 6 [net] => 25 [tie] => yes ) [194] => Array ( [s_id] => 11 [pid] => 194 [ppoints] => 7 [net] => 25 [tie] => yes ) ) ) This array is the strokes achieved by each golfer. So you have the unique id and then h1 is hole1 and so on. Array ( [189] => Array ( [h1] => 4 [h2] => 4 [h3] => 5 [h4] => 4 [h5] => 5 [h6] => 4 [h7] => 3 [h8] => 5 [h9] => 5 ) [203] => Array ( [h1] => 4 [h2] => 4 [h3] => 5 [h4] => 5 [h5] => 5 [h6] => 5 [h7] => 4 [h8] => 5 [h9] => 5 ) [190] => Array ( [h1] => 4 [h2] => 4 [h3] => 4 [h4] => 4 [h5] => 4 [h6] => 4 [h7] => 4 [h8] => 4 [h9] => 4 ) [204] => Array ( [h1] => 5 [h2] => 4 [h3] => 4 [h4] => 4 [h5] => 5 [h6] => 5 [h7] => 5 [h8] => 4 [h9] => 6 ) [191] => Array ( [h1] => 4 [h2] => 4 [h3] => 4 [h4] => 3 [h5] => 4 [h6] => 4 [h7] => 4 [h8] => 4 [h9] => 5 ) [201] => Array ( [h1] => 4 [h2] => 4 [h3] => 4 [h4] => 4 [h5] => 4 [h6] => 4 [h7] => 4 [h8] => 4 [h9] => 4 ) [192] => Array ( [h1] => 4 [h2] => 4 [h3] => 4 [h4] => 4 [h5] => 4 [h6] => 4 [h7] => 4 [h8] => 4 [h9] => 4 ) [202] => Array ( [h1] => 4 [h2] => 4 [h3] => 4 [h4] => 5 [h5] => 4 [h6] => 4 [h7] => 4 [h8] => 4 [h9] => 4 ) [193] => Array ( [h1] => 4 [h2] => 5 [h3] => 4 [h4] => 4 [h5] => 4 [h6] => 4 [h7] => 4 [h8] => 4 [h9] => 4 ) [199] => Array ( [h1] => 5 [h2] => 4 [h3] => 4 [h4] => 4 [h5] => 4 [h6] => 4 [h7] => 4 [h8] => 4 [h9] => 4 ) [194] => Array ( [h1] => 4 [h2] => 4 [h3] => 5 [h4] => 4 [h5] => 4 [h6] => 4 [h7] => 4 [h8] => 4 [h9] => 4 ) [200] => Array ( [h1] => 4 [h2] => 4 [h3] => 4 [h4] => 4 [h5] => 4 [h6] => 4 [h7] => 4 [h8] => 4 [h9] => 4 ) [195] => Array ( [h1] => 5 [h2] => 5 [h3] => 5 [h4] => 5 [h5] => 5 [h6] => 5 [h7] => 5 [h8] => 5 [h9] => 5 ) [197] => Array ( [h1] => 5 [h2] => 5 [h3] => 5 [h4] => 5 [h5] => 5 [h6] => 5 [h7] => 5 [h8] => 5 [h9] => 6 ) [196] => Array ( [h1] => 5 [h2] => 5 [h3] => 5 [h4] => 5 [h5] => 5 [h6] => 5 [h7] => 5 [h8] => 5 [h9] => 5 ) [198] => Array ( [h1] => 5 [h2] => 5 [h3] => 5 [h4] => 5 [h5] => 5 [h6] => 5 [h7] => 5 [h8] => 5 [h9] => 5 ) ) So here's what needs to happen. Those 3 in the first division who have ties need to compare scores. So first hole 193 and 191 got 4 sonot they move to the second hole. 191 got a 4 so he ranks first so 193 would rank second and 199 would be third. I need a loop to compare all thrugh the 9 holes just in case it goes till the end. Hope I explained it well enough. Thanks in advance for the help.