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

  • Home
  • SEARCH
  • 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 7191615
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:46:01+00:00 2026-05-28T19:46:01+00:00

I have 2 columns in a table called Points. The 2 columns are UserPoints

  • 0

I have 2 columns in a table called Points. The 2 columns are UserPoints and UserID.

I want to be able to echo the total amount of points a user has.

I’ve got something like this but I dont think its right.

$getTotalPoints = mysql_query("SELECT SUM(UserPoints) FROM `Points` WHERE `UserID` = '1'") or die(mysql_error()); 
$totalPoints = mysql_fetch_array($getTotalPoints);

When i echo the above statement by echoing “$totalPoints” i get “Array”.

Anyone know the correct query to do this ?

  • 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-28T19:46:02+00:00Added an answer on May 28, 2026 at 7:46 pm

    You’re getting Array because that’s what’s stored in $totalPoints. Look closely at your code and you’ll see you used the mysql_fetch_array() function, which retrieves a row of results from the results set as an array. If you do var_dump() on $totalPoints you’ll see the following:

    Array
    (
        [0] => 12345
        [SUM(UserPoints)] => 12345
    )
    

    The sum you’re looking for is at index 0 or the column name, in this case SUM(UserPoints), so you can output it using echo $totalPoints[0] or echo $totalPoints['SUM(UserPoints)'].

    Alternatively, you could use the mysql_result() function. I think this is more in-line with the behavior you were expecting. It fetches a single value from the row from the result set. So, instead of mysql_fetch_array() you’d wrote:

    $totalPoints = mysql_result($result, 0);
    

    For more information on mysql_result(), check out the PHP documentation for it.

    As an aside, I would recommend not using mysql_* functions if you have the option. A newer interface like PDO, or at least mysqli, would be better. This will depend on your project of course… if you’re working with a large legacy code base it may be difficult to change. But if you’re starting out now, I think you’d benefit from the newer libraries. You can see my opinion and some guidance on transitioning extensions in this article I wrote.

    Hope this helped… and good luck!

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

Sidebar

Related Questions

I have a table called scheduler_sched which has several columns, including a column called
I have a table called ProjectRegion. It has two columns, an id and a
I have a table called trends_points , this table has the following columns: id
I have a table called pano_raw that has 3 columns lat, lng, and latlng.
I have a table called Point. The table has two columns that we'll deal
Assume I have a table called table and I have 3 columns, a, b,
I have a table called Table with columns: ID (int, primary key, clustered, unique
I have a table called tblRentalRates with the following columns: rate_id (int) rate_startdate (datetime)
I have a legacy MySQL table called lnk_lists_addresses with columns list_id and address_id .
I have a table called Event. A column has duration--which is...how long that event

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.