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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:47:44+00:00 2026-05-17T21:47:44+00:00

Apologies if I should know better, but I’ve been struggling for quite a while

  • 0

Apologies if I should know better, but I’ve been struggling for quite a while with this one.

I have a mysql db with 300 rows. It contains 4 columns, "eventid", "player1", "player2", "score". In the game, player1 gives various others (player2) a score out of 100.

What I’m trying to do is show the logged in user (player1) a table of the "player2"s they have scored.

My code looks like this:

$currentuserid = 00001;

$opponent_data = mysql_query("SELECT * FROM `scores` WHERE `player1` = $currentuserid ORDER by score");

$opponent_count = mysql_num_rows($opponent_data);

    echo $opponent_count.'<br>'; // Just to test -> and it shows I have 144 entries in the array, i.e. 144 player 2's that player 1 has scored

$opponent_scores = mysql_fetch_assoc($opponent_data);

$runrows = $opponent_scores;

foreach ($opponent_scores as &$runrows);

    {
    $id = $runrows['eventid'];
    $player2 = $runrows['player2'];
    $score = $runrows['score'];


    echo $player2." got ".$score;

    echo "<br>";

    }

When I run this all I can see is

144

73 got 44

but I was hoping to see 144 rows of "player 2" got "player 2’s score".

What am I doing wrong?

  • 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-05-17T21:47:45+00:00Added an answer on May 17, 2026 at 9:47 pm

    In addition: mysql_fetch_assoc will only return the pointer to your first row in the resultset. That is why you’ll end up with only one row being printed.

    Change your code to:

    while($opponent=mysql_fetch_assoc($opponent_data)) {
         echo $opponent['player2']." got ".$opponent['score'];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First, apologies,this should be simple but I've had too much coffee and cannot wrap
have Googled the cr*p out of this one so apologies if the answer is
Apologies in advance for the long-winded question. I'm really a database programmer, but have
Apologies if this is too ignorant a question or has been asked before. A
Apologies if this question is a bit obscure, I've been banging my head against
My apologies if similar questions already exist (I know they do), but I didn't
Unsure if this should be on here or serverfault so apologies if I'm wrong.
Apologies if this has been asked before, and it's hard to imagine it hasn't,
This should be a simple matter, but for some reason I can't grasp it.
Apologies if this has been asked before. I searched and couldn't find it. In

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.