Jump to content

Recommended Posts

I know that this will not work...but here's what I have:

<?php
$user = Zack;
function getRank($user){
$query = "SELECT * FROM user ORDER BY score";
$rank = 0;
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)){
$rank++;
$user_rank = "$rank WHERE username='$user'";
}
}
?>

What I'm trying to do is make it find the rank for every user but store the one for a certain user (Zack).

 

If anyone knows how I can make that work or a better way to do it, please post here :P

Link to comment
https://forums.phpfreaks.com/topic/115745-solved-phpmysql-rankings/
Share on other sites

Well, I'm not sure if this would work but I was messing around and I came up with this:

<?php
$user = Zack;
function getRank($user){
$query = "SELECT * FROM user";
$rank = 0;
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)){
$rank++;
$test_rank[" . $row['username'] . "] = $rank;
echo $test_rank[$user];
}
}
getRank($user);
?>
Anyone Know if that'd work?

function getRank ($user)
{
    $sql = "SELECT COUNT(*)+1 as rank 
            FROM user
            WHERE score > (SELECT score FROM user WHERE username = '$user')";
    $res = mysql_query($sql);
    return mysql_result($res,0);        
}

$rank = getRank('Zack');
echo $rank;

 

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.