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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T04:20:11+00:00 2026-05-11T04:20:11+00:00

Anyone knows how to get sum of number? For example i have mysql column

  • 0

Anyone knows how to get sum of number?

For example i have mysql column name package.

Package 3 4 1 3 4 

If package 3, the value should be usd 5, if package 4, value should be usd 10, if package 1, value should be usd 1 and so on.

So the total value above should be => 5 + 10 + 1 + 5 + 10 = 31

So how do i get sum of it in php?

i tried array_sum .. but it gives me error, im not very expert in php.. Please help me

Thanking in advance.

  • 1 1 Answer
  • 1 View
  • 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. 2026-05-11T04:20:11+00:00Added an answer on May 11, 2026 at 4:20 am

    Get the database to do the work:

    select sum(CASE WHEN package = 3 THEN 5 ELSE 0 END)        + sum(CASE WHEN package = 4 THEN 10 ELSE 0 END)        + sum(CASE WHEN package = 1 THEN 1 ELSE 0 END) AS total from table_name 

    The right way of doing it, if you’ve got more than a few values be to modify the table to contain the amount field so you can do:

    select sum(amount) from table_name 

    Alternatively have another table that you contained the relationship between the values (package, amount), and then do

    select sum(package_amount)  from table_name, lookup_values where table_name.package = lookup_values.package 

    Or, if you really want to do it in PHP:

    $amount = array(3=>5, 4=>10, 1=>1);  // define the amount of each value $result = mysql_query('SELECT id FROM table_name'); $sum = 0;  while ($row = mysql_fetch_assoc($result)) {     $sum += $amount[ $row['id'] ]; } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Anyone knows how to get the current host name from a Cray Fortran program?
Anyone knows how to get selected text from other application using UI Automation and
Just wondering whether anyone knows how to get blogger labels into alt tags in
I was wondering if anyone knows how to get formatted or styled codes from
Does anyone knows how i can get buyer's reviews from a Product in a
I'm curious if anyone knows of a way to easily get a double border
I know I can get answers here but I was wondering if anyone knows
Anyone knows other way to get a directoy's size, than calculate it's size by
I have a problem with a MySQL statement: select sum(x) as sum, 01.06.2010 as
I'm trying to add all the values in a column to get the total

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.