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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:22:45+00:00 2026-06-14T05:22:45+00:00

I have a multi-column table that holds scores for games. The format is that

  • 0

I have a multi-column table that holds scores for games. The format is that each score has a gameid number attached to it. I then find the highest score for each gameid and display it. The problem is that if a game is deleted and the the gameid numbers are no longer consecutive, it will display 2 of the same high score for the game. An example would be a score of 5000 for gameid 3, 6000 for gameid 4, and 3200 for gameid 5. If I delete gameid 4, the output would be 5000-3, 5000-3, 3200-5.I obviously don’t want it to output 2 of the same score. Below is the PHP code I use to do this:

<?php

echo '<table cellpadding="0" class="content" cellspacing="0" width="100%" >';
echo '<tr><th>Game</th><th>Initials</th><th>Score</th><th>Date</th></tr>';

include("includes/sqlconnect.inc");
include("includes/functions.php");
$idnum=1;

    $allscores = mysql_query("SELECT * FROM scores");
    $highid = array(
    );
    while($row = mysql_fetch_array( $allscores ))
    {
    $idnums=$row['gameid'];
    $highid[]=$idnums;      
    }
while($idnum<=max($highid))
{
    $allscores = mysql_query("SELECT * FROM scores WHERE gameid ='$idnum'");
    $array = array(
    );
    while($row = mysql_fetch_array( $allscores ))
    {
    $score=$row['score'];
    $scoreid=$row['scoreid'];
    $array[$scoreid]=$score;      
    }
    $high=doublemax($array);
    $nameid = mysql_query("SELECT scoreid,playerid,score FROM scores WHERE scoreid='$high[i]'");
    while($row = mysql_fetch_array($nameid))
    {
    $player=$row['playerid'];
    }
    $dateid = mysql_query("SELECT scoreid,date FROM scores WHERE scoreid='$high[i]'");
    while($row = mysql_fetch_array($dateid))
    {
    if($row['date']=="")
    {
            $date="Unknown";
    }
    else
    {
            $date=$row['date'];
    }
    }
    $name = mysql_query("SELECT playerid,player_initials FROM players WHERE playerid='$player'");
    while($row = mysql_fetch_array($name))
    {
    $initials=$row['player_initials'];
    }
    $gamename = mysql_query("SELECT gameid,gamename FROM games WHERE gameid='$idnum'");
    while($row = mysql_fetch_array($gamename))
    {
    $game=$row['gamename'];
    }

    $idnum++;

            echo "<tr>";
            echo '<td>'.$game.'</td>';
            echo '<td>'.$initials.'</td>';
            echo '<td>'.number_format($score).'</td>';
            echo '<td>'.$date.'</td>';      
    echo "</tr>";

    }

echo "</table>";

?>
  • 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-14T05:22:46+00:00Added an answer on June 14, 2026 at 5:22 am

    The problem is you’re basing the number of outputs on the id rather than the number of rows of data returned.

    Rather than getting the max score later get that during your initial query

     $allscores = mysql_query("SELECT field1, field2, MAX(score) FROM scores GROUP BY gameid"); // I don't know the field names you need obviously place those instead of field1 etc.
    

    Then base your main loop on a foreach rather than a while.

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

Sidebar

Related Questions

We have a log table that has a message column that sometimes has an
I have a table that has a column named 'languages', but it has the
I have created a multi column datastore on a table that allows me to
I need to get the last inserted id of table that have multi-column primary
I have a custom, multi-column sort attached to my jqGrid instance by means of
i have this multi dimentional array that i want to print into a table
In SSRS I have a report parameter that is a multi-select and has a
I am building a multi language site I have a descriptions table that hold
In a multi-tenant application I have a table with TenantId column. This table is
I have an invoice table that has InvoiceID (int identity ) Primary key. and

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.