I'm trying to make a golfleaderboard, and have that under control, but now I want to show the leaderboard for the current user and the 5 above the user and the 5 below... Here is how its shown at this time... $currentUser = $row['userid']; echo '<table cellpadding="0" cellspacing="1"> <tr> <td width="10%" valign="middle" bgcolor="#669900"><div style="padding:3px;color:#FFFFFF;text-align:center;">P</div></td> <td width="80%" align="left" valign="middle" bgcolor="#669900"><div style="padding:3px;color:#FFFFFF;">'._PLAYER.'</div></td> <td width="10%" align="center" valign="middle" bgcolor="#669900"><div style="padding:3px;color:#FFFFFF;text-align:center;">'._POINTS.'</div></td> </tr>'; $sql = "SELECT u.fname, u.lname, u.country, user_points.points FROM ".$prefix."_users cu INNER JOIN ".$prefix."_users u ON u.new_userid = cu.new_userid INNER JOIN ".$prefix."_GA_users ON u.new_userid = ".$prefix."_GA_users.userid INNER JOIN ( SELECT AVG(point) points, userid FROM ".$prefix."_GA_leaderboard WHERE seasonid = $seasonid GROUP BY userid ) user_points ON cu.new_userid = user_points.userid WHERE ".$prefix."_GA_users.aproved = 1 ORDER BY user_points.points DESC LIMIT 25"; $result = mysql_query($sql); $x = 0; $i = 0; $prev = 0; $r_count = 0; while($row = mysql_fetch_array($result)){ $fname = $row['fname']; $lname = $row['lname']; $ucountry = $row['country']; $sql2 = "SELECT * FROM ".$prefix."_geo_countries WHERE con_id='$ucountry'"; $result2 = mysql_query($sql2); $row2 = mysql_fetch_array($result2); $curr = $row['points']; if ($curr != $prev) { $i = $x + 1; } echo '<tr style="background-color:#' .((++$r_count %2 == 0) ? 'FFFFFF' : 'EEEEEE'). '">'; echo '<td 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 align="left" valign="middle"> '; if(!$row['country']) { echo '<img src="http://www.golfacross.com/facebook/images/lang/nocountry.png"> '; } else { echo '<img src="http://www.golfacross.com/facebook/images/lang/'.$row2['iso'].'.png"> '; } echo ''.$fname.' '.$lname.'</td>'; echo '<td align="center" valign="middle"><div style="text-align:center;">' . number_format($row['points'], 2) . '</div></td>'; echo '</tr>'; $prev = $curr; $x++; } echo '</table>'; echo '</div>'; PHP: As it is now it shows the top 25 on the leaderboard, but if the current user is placed lets say as number 247 he is either not shown or I would have to make an long scrolling print... Any help please...
I have no idea what is going with your SQL statement but maybe making use of LIMIT in two statements. Forwards SELECT * FROM `your_table` LIMIT 247, 5 This will show records 248, 249, 250, 251, and 252 Code (markup): Backwards SELECT * FROM `your_table` LIMIT (247-5), 5 This will show records 242, 243, 244, 245 and 246 Code (markup):
Then I have to now before printing what number the user is?!? and can your 2 example be put together into one?
Nope... As it is now it just calculates the users points in the sql query and then order ASC. It doesnt actuelly comes with the number the user is! INNER JOIN ( SELECT AVG(point) points, userid FROM ".$prefix."_GA_leaderboard WHERE seasonid = $seasonid GROUP BY userid ) user_points PHP: And then before loop: $x = 0; $i = 0; $prev = 0; $r_count = 0; while($row = mysql_fetch_array($result)){ PHP: I should problary somehow find out how many users/player which is higher placed than the user and get that number in the same sql query, but I don't know how...