Petsmacker Posted November 23, 2006 Share Posted November 23, 2006 Basically I have a website where people are sorted into one of 4 teams when they join and throughout 2 months they earn points - the team with most points at the end of the month are the winners - easy.What I want is Something like this:[table][tr][td]TEAM[/td][td]Team 1[/td][td]Team 2[/td][td]Team 3[/td][td]Team 4[/td][/tr][tr][td]POS.[/td][td][center]3[/center][/td][td][center]1[/center][/td][td][center]2[/center][/td][td][center]4[/center][/td][/tr][/table]So POS would mean what position they had come at the end of the month when I close the game. The only problem is that sometimes houses can get the same amount of points so in that case the positions should be like:[table][tr][td]TEAM[/td][td]Team 1[/td][td]Team 2[/td][td]Team 3[/td][td]Team 4[/td][/tr][tr][td]POS.[/td][td][center]2[/center][/td][td][center]1[/center][/td][td][center]2[/center][/td][td][center]3[/center][/td][/tr][/table]for exampleI've tried using tons of IF statements but when it came to the houses having equal points in some instances it made things too complicated for me. I hope somebody can help! Quote Link to comment Share on other sites More sharing options...
Petsmacker Posted November 23, 2006 Author Share Posted November 23, 2006 Sorry, having to post again to bump cos I fear this is being lost and I really need help with it.I'll continue to try and get it but... Quote Link to comment Share on other sites More sharing options...
ataria Posted November 23, 2006 Share Posted November 23, 2006 Make a column in the user table.. named 'team'and make it enter a random number (for the team, 1-4)then.. make a table 'points' and make 4 columns.. Team 1, Team 2, Team 3, and Team 4. and thisz will be the totals for all of them.so, if you want to give team 1 a point, you +1 to the team 1 column.. and, such.if you want to record each users contribution, make a 'points' column in the USER table.and, then make it +1 everytime they contribute a point ALSO make sure it +1's their teams points aswell.I hope that wasn't too confusing... Quote Link to comment Share on other sites More sharing options...
Petsmacker Posted November 23, 2006 Author Share Posted November 23, 2006 Hey, thanks for your contribution but I didn't mean the points themselves. I meant their position. So the team with the most points - in the 'Pos' column would be '1', 2nd would be 2 etc. Quote Link to comment Share on other sites More sharing options...
ataria Posted November 23, 2006 Share Posted November 23, 2006 Hey, thanks for your contribution but I didn't mean the points themselves. I meant their position. So the team with the most points - in the 'Pos' column would be '1', 2nd would be 2 etc.List it in descending order :] Quote Link to comment Share on other sites More sharing options...
Petsmacker Posted November 23, 2006 Author Share Posted November 23, 2006 The layout of my database doesn't work like that, if it did I really wouldn't have a problem.Each user in their row of the database has what team they're in and how many points they've personally earnt this month. This is then tallied up for each person in each team to come to the team totals. So I can't do it that way. And plus, even if I did do it in descending order, it would allow team positions such as 1,2,3,3 if two teams had the same amount of points. Quote Link to comment Share on other sites More sharing options...
ataria Posted November 23, 2006 Share Posted November 23, 2006 If two teams tied, there would be no 4th place...you can also do it manually. Quote Link to comment Share on other sites More sharing options...
Petsmacker Posted November 23, 2006 Author Share Posted November 23, 2006 Right, thanks...think I'll do a bit of work with some IF statements and see what I come out with. Quote Link to comment Share on other sites More sharing options...
mansuang Posted November 23, 2006 Share Posted November 23, 2006 Hi,Hope my code is right for you.[code]<?php//example data $arr = array("team1"=>200, "team2"=>100, "team3"=>200, "team4"=>300);//sort and array in reverse orderarsort($arr);//define score$score = 5;//loopforeach($arr as $key=>$val){ if($tmp_val!=$val){ $score--; $d[$key]=$score; }else{ $d[$key]=$score; } $tmp_val = $val;}//checking valueprint_r($d);?>[/code]You may modify some code for forward order:- arsort($arr); to asort($arr);- $score = 5; to $score = 0;- $score--; to $score++; Quote Link to comment Share on other sites More sharing options...
Petsmacker Posted November 23, 2006 Author Share Posted November 23, 2006 You legend. Thats exactly what I was asking for, perfectisimo. Have got it going now. Thankyou! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.