Assign points depending on rank?!

Discussion in 'PHP' started by jmansa, Mar 26, 2009.

  1. #1
    I have this script which list playes with some results. The player with the highest totalpoints ($tpoints) at top and so on... That part works like a charm.

    Now each player is assigned bonuspoints ($bonuspoints) depending on the rank, and that part works ok to, but...

    If 2 players have the same point, let's say #1 and #2, it gives both these players points as they both are number one, in this case 7 bonus points. What I would like is that, since in this case there are 2 players, is to add bonuspoints 7 and 4, divede it by 2 and then round it up (7+4=11/2=5,5, roundup to 6) and then assign these points to them... Is this possible? and if yes... How?

    			$xtrapoints = array(7,4,2,1,0);
    			
    			$x = 0; 
    			$i = 0; 
    			$prev = 0;
    			$r_count = 0;
    			
    			while($row = mysql_fetch_array($result)){ 
    			
    				$curr = $row['p_total']; 
    				if ($curr != $prev) 
    				{ 
    					$i = $x + 1; 
    				} 
    				
    				$player = $row['new_userid'];
    				$fname = $row['fname'];
    				$lname = $row['lname'];
    				$tpoints = $row['p_total'];
    				$tstroke1 = $row['stroke_total'];
    				$tstroke2 = ($tstroke1 - $row['xtrastrokes']);
    				
    				$bonuspoints = ($i < count($xtrapoints)) ? $xtrapoints[$i-1] : 0;
    				
    				if ($tpoints >= 30){
    					$totalpoints = ($bonuspoints + ($tpoints - 30));
    				} else {
    					$totalpoints = $bonuspoints;
    				}
    				
    					
    				 echo '<tr style="background-color:#' .((++$r_count %2 == 0) ? 'FFFFFF' : 'EEEEEE'). '">';
    				 echo '<td width="" align="center" valign="middle"><input name="placement[]" type="text" readonly="true" value="'.$i.'" style="font-size:11px;width:16px;text-align:center;border:none;background-color:transparent;font-family:lucida grande,tahoma,verdana,arial,sans-serif;"/></td>';
    				 echo '<td width="" align="left" valign="middle">&nbsp;'.$fname.' '.$lname.'</td>';
    				 echo '<td width="" align="center" valign="middle">'.$tstroke1.'</td>';
    				 echo '<td width="" align="center" valign="middle">'.$tstroke2.'</td>';
    				 echo '<td width="" align="center" valign="middle">'.$tpoints.'</td>';
    				 echo '<td width="" align="center" valign="middle">'.$bonuspoints.'</td>';
    				 echo '<td width="" align="center" valign="middle"><input name="points[]" type="text" readonly="true" value="'.$totalpoints.'" style="font-size:11px;width:16px;text-align:center;border:none;background-color:transparent;font-family:lucida grande,tahoma,verdana,arial,sans-serif;"/><input type="hidden" name="player[]" value="'.$player.'"></td>';
    				 echo '</tr>';
    			
    				$prev = $curr; 
    				$x++; 
    			
    			}
    PHP:
    Thanks:)
     
    jmansa, Mar 26, 2009 IP
  2. bartolay13

    bartolay13 Active Member

    Messages:
    735
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    98
    #2
    why not lose that equation and order them by when their are ranked. i mean update time in your database. just a thought
     
    bartolay13, Mar 27, 2009 IP