Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.