Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9041795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T10:19:29+00:00 2026-06-16T10:19:29+00:00

I know this been asked many times here, been through most of the posts

  • 0

I know this been asked many times here, been through most of the posts here, but I can’t get it working so thought to ask it again.

The problem:
There’s a score list, I’m trying to show user what’s his/her position in the score list. There’s a player_id, user is selected from two tables(players.id, scores.player_id). I’ve never tried such query, I wrote sth like this based on the instruction given in this site but no luck, this query isn’t right, kinda lost here.

SELECT 
    @rn:=@rn + 1 AS rank, scores.score
FROM
    (SELECT 
        scores.score, COUNT(*) AS ordercount
    FROM
        scores, players
    WHERE
        players.uid = '$uid'
            AND scores.version = '$version'
            AND scores.lvl = '$lvl'
            AND scores.player_id = players.id
    GROUP BY scores.score
    ORDER BY scores.score DESC) t1,
    (SELECT @rn:=0) t2

Result:

Unknown column 'scores.score' in 'field list

thanks!

Score table Structure:

CREATE TABLE IF NOT EXISTS `scores` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `player_id` int(11) NOT NULL,
  `lvl` tinyint(4) NOT NULL,
  `score` bigint(20) NOT NULL,
  `played_times` bigint(20) NOT NULL,
  `version` varchar(10) NOT NULL,
  `ip` varchar(30) NOT NULL,
  `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB;

—

— Dumping data for table scores

INSERT INTO `scores` (`id`, `player_id`, `lvl`, `score`, `played_times`, `version`, `ip`, `timestamp`) VALUES
(1, 1, 1, 9990, 4, '1', 'xx.xx.xx.xxx', '2012-12-24 01:46:10'),
(2, 1, 2, 5750, 1, '1', 'xx.xx.xx.xxx', '2012-12-24 01:46:49'),
(3, 1, 1, 10290, 5, '1', 'xx.xx.xx.xxx', '2012-12-24 02:47:25'),
(6, 1, 1, 13620, 6, '1', 'xx.xx.xx.xxx', '2012-12-24 10:40:26'),
(7, 2, 2, 241251, 2, '1', 'xx.xx.xx.xxx', '2012-12-24 19:03:22');

Player table Structure:

CREATE TABLE IF NOT EXISTS `players` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(20) NOT NULL,
  `email` varchar(255) NOT NULL,
  `pass` varchar(255) NOT NULL,
  `hash` varchar(255) NOT NULL,
  `uid` varchar(255) NOT NULL,
  `ip` varchar(30) NOT NULL,
  `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB;

—

— Dumping data for table scores

INSERT INTO `players` (`id`, `name`, `email`, `pass`, `hash`, `uid`, `ip`, `timestamp`) VALUES
(1, 'Test', 'TEST@TEST.COM', '', '51516h0c0', '7b3bd627c9b0', 'xx.xx.xx.xxx', '2012-12-24 00:56:38');

PHP;

/*
    get player's topscore position among others
*/
function _getPlayerTopScorePos($uid,$lvl,$version)
{
    $uid            = _jClean($uid);
    $version        = _jClean($version);
    $lvl            = _jClean($lvl);

    include 'db.inc.php';

    $q = mysql_query("SELECT 
        @rn:=@rn + 1 AS rank, t1.score
    FROM
        (SELECT 
            scores.score, COUNT(*) AS ordercount
        FROM
            scores, players
        WHERE
                players.uid = '$uid'
                AND scores.version = '$version'
                AND scores.lvl = '$lvl'
                AND scores.player_id = players.id
        GROUP BY scores.score
        ORDER BY scores.score DESC) t1,
        (SELECT @rn:=0) t2");

    echo mysql_error();

    $x = mysql_fetch_array($q);
    $a = $x["rank"];

    @mysql_close();

    return $a;  
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T10:19:30+00:00Added an answer on June 16, 2026 at 10:19 am

    What if you change the table reference from scores to t1, since you’re using an alias to the subquery?

    SELECT 
            @rn:=@rn + 1 AS rank, t1.score
        FROM
            (SELECT 
                scores.score, COUNT(*) AS ordercount
            FROM
                scores, players
            WHERE
                players.uid = '$uid'
                    AND scores.version = '$version'
                    AND scores.lvl = '$lvl'
                    AND scores.player_id = players.id
            GROUP BY scores.score
            ORDER BY scores.score DESC) t1,
            (SELECT @rn:=0) t2
    

    — edit

    SELECT COUNT(t1.player_id)
        FROM
            (SELECT 
                scores.player_id
            FROM
                scores
                INNER JOIN players ON scores.player_id = players.id
            WHERE
                players.uid = '$uid'
                AND scores.version = '$version'
                AND scores.lvl = '$lvl'
                AND scores.player_id = players.id
                AND scores.score >= '$score'
            GROUP BY scores.player_id) t1 
    

    You can do a separate query returning the number of users playing and display ie. 25/100

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know this has been asked many times before, but i still can't seem
I know this has been asked many times, but I can't find an answer
I know this question has been asked many times before but I can't find
I know this question has been asked many times on SO, but I can't
I know this question has been asked many times here, but no answer has
I know this question has been asked many times on here but I have
I know this question has probably been asked so many times here, but I
I know this question has been asked many times, but here are my specific
I know this has been asked many times, but I can not understand this
I know this has been asked many times but i'm yet to find a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.