# How to calculate numbers in a certain column

4 replies to this topic

### #1 shazly

shazly
• New Members
• Newbie
• 2 posts
• Locationthe glob

Posted 18 May 2006 - 07:16 AM

i have this table "my_points" in my database. it has two cloumns,

1- points_id
2- points

i have 20 entries in this table, in the second col. i have numbers in each entry (just plain numbers), i.e 232

now how do i calculate the total allover the 20 entries?

i wrote code below but it didn't work out with me

```//after connection

\$totalsize = mysql_query("SELECT * FROM my_points");
\$totalsizenum = mysql_num_rows(\$totalsize);
while(\$totalsizerow = mysql_fetch_array(\$totalsize)){
\$allofit = print("\$totalsizerow[size] + 1");
}
```

### #2 .josh

.josh
• Staff Alumni
• .josh
• 14,871 posts

Posted 18 May 2006 - 07:41 AM

\$result = mysql_query("SELECT count(points) as total FROM my_points");
\$totalpoints = mysql_fetch_array(\$result);
echo \$totalpoints['total'];

Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you \$5-\$15/hr. A decent entry level freelancer will charge you around \$15-30/hr. A professional will charge you anywhere from \$50-\$100/hr. An agency will charge anywhere from \$100-\$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community

### #3 Barand

Barand
• Moderators
• Sen . ( ile || sei )
• 18,021 posts

Posted 18 May 2006 - 09:50 AM

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]SELECT count(points) as total FROM my_points[/quote]

will give then number of non-null values in the "points" column.

`SELECT SUM(points) as total FROM my_points`

will give the total of the values in the "points" column.

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

 |baaGrid| easy data tables - and more|baaChart| easy line, column and pie charts

### #4 shazly

shazly
• New Members
• Newbie
• 2 posts
• Locationthe glob

Posted 18 May 2006 - 12:33 PM

thanks alot barand and Crayon Violet

### #5 .josh

.josh
• Staff Alumni
• .josh
• 14,871 posts

Posted 18 May 2006 - 07:16 PM

oops i really meant sum thx barand