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 9135353
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:48:47+00:00 2026-06-17T08:48:47+00:00

I have a PHP game which uses a MySQL table (history) that keeps track

  • 0

I have a PHP game which uses a MySQL table (history) that keeps track of users and how many times they knew the answer like:

username answer
-------- ------
user1    answer1
user2    answer2
user1    answer3

etc. And I want to use this table to print the best players, so I’m trying to implement an array like

public function getBestPlayers($hrows) /*history_rows*/
{
$ray=array();
$hlen = count($hrows);

for($i=0;$i<$hlen;$i++)
{
    $curnick = $hrows[$i]['knower'];
    $ray[$curnick]; //my attempt to "set" the index
    if($ray[$curnick]!=NULL)
    {
        $ray[$curnick]++;
    }
    else
    {
        $ray[$curnick]=1;
    }
}//for
$ray = sort($ray);
return $ray;
}//getBestPlayers()

so that in the end I have $ray['user1'] = 2 , $ray['user2'] = 1 etc.
But this gives error “undefined index: user1”.
what should I do?
thanks in advance..

  • 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-17T08:48:48+00:00Added an answer on June 17, 2026 at 8:48 am

    You should let MySql do this for you, which will be much faster and much easier:

    SELECT username, COUNT(*) AS score FROM tbl GROUP BY username ORDER BY score DESC
    

    This will return a result set of the form

    username score
    -------- ------
    user1    2
    user2    1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this script which uses PHP PDO to access the MySQL database, but
I have made a game which is nearly identical to Popcap's Atomica. ( http://www.popcap.com/gamepopup.php?theGame=atomica
I have a simple JavaScript game that sends a score to PHP by adding
I have php script that creates a temporary watermark image for users that are
We're devoloping a flash game which have a php and mongodb backend.. It's kinda
One of our customers said they have a very simple script which uses fsockopen()
I have a Facebook game titled Rails Across Europe. It is written in PHP/MySQL/Facebook
I have this function, that it's part of my game, and which sends the
Say I have a game in PHP which is a money making game and
I have a Flash based game for the browser which sends users' scores to

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.