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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T21:03:19+00:00 2026-06-06T21:03:19+00:00

I have one query where the output processing looks like this: while($row = mysql_fetch_array($result)){

  • 0

I have one query where the output processing looks like this:

 while($row = mysql_fetch_array($result)){
    echo $row['username'] . " " . $row['earning'];
 }

And outputs result is like this:

 JOHN  200
 JOHN  350
 NEO   100
 NEO   220

What I want to achieve is that every name appears once, and “earning” is sum of all earnings of that name, like this:

 JOHN 550
 NEO  320

I have to mention that I CANNOT change the query; that is biggest problem.

Is there any hope? Some suggestions? 🙂

  • 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-06T21:03:22+00:00Added an answer on June 6, 2026 at 9:03 pm

    You can sum the values in the loop to another array and then output it.

    Try:

    $earnings = array();
    
    while($row = mysql_fetch_array($result)) {
        if (!isset($earnings[$row['username']])) $earnings[$row['username']] = 0;
        $earnings[$row['username']] += $row['earning'];
    }
    
    foreach($earnings as $user => $earnings) {
        echo "$user  $earnings<br />\n";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one object being the result of a database query, looking something like
I have one query on which I would like to get your valuable feedback.
I have a query that always returns one row, with many columns. I would
I have a query that returns one row. However, I want to invert the
I have a query that returns a result set similar to the one below:
I have one query in SQL Server output, Suppose i have one table (Ex.StudentMaster)
I have a LINQ query written to pull at least one row from a
I have one query. Through while loop I am displaying three random songs from
Given this output to one query: ID | Question | Answer 1 | 1
I have a table that looks like: What I want to do is output

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.