Jump to content

Display rank value


lukep11a

Recommended Posts

Hi, I am running a fantasy football league and on a users account page I want to display what rank that user currently is overall, does anybody know how I can modify the code below to display the rank of the current user?

 

<?php
        $query = "SELECT SUM(teams.points) FROM selections, teams WHERE selections.userid = '{$_SESSION['userid']}' AND (selections.groups = teams.groups)";
        $result = mysql_query($query) or die(mysql_error());
        
        $row = mysql_fetch_assoc($result);
        ?>
        <p class="scoring"><?php echo $row['SUM(teams.points)']; ?></p>

Link to comment
https://forums.phpfreaks.com/topic/242368-display-rank-value/
Share on other sites

This is the code that grabs all rows and orders by sum of the points, do you know how I can print what number row the current user is??

 

<?php

	$query = "SELECT SUM(teams.points) FROM login, selections, teams WHERE login.userid = selections.userid AND selections.groups = teams.groups GROUP by login.userid ORDER by SUM(teams.points) DESC";

	$result = mysql_query($query) or die(mysql_error());
	while($row = mysql_fetch_assoc($result))
        {

        }
        ?>

Link to comment
https://forums.phpfreaks.com/topic/242368-display-rank-value/#findComment-1244858
Share on other sites

I have read that and it was helpful, thanks, but it is slightly different to what I am trying to do. I have now included a variable in my code to count the rows, but do you know how I would display the number of the row for the current user (i.e where the session userid = login.userid)? It is currently displaying the number '1'

 

<?php

	$query = "SELECT SUM(teams.points) FROM login, selections, teams WHERE login.userid = selections.userid AND selections.groups = teams.groups GROUP by login.userid ORDER by SUM(teams.points) DESC";

	$result = mysql_query($query) or die(mysql_error());
	$counter = 1; // set a counter value
	$row = mysql_fetch_assoc($result);
        ?>
        <p class="scoring"><?php echo $counter; //output the counter ?></p>

Link to comment
https://forums.phpfreaks.com/topic/242368-display-rank-value/#findComment-1244888
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.