Jump to content

How to calculate numbers in a certain column


shazly

Recommended Posts

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

[code]
//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");
}
[/code]
Link to comment
Share on other sites

[!--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.


[code]SELECT SUM(points) as total FROM my_points[/code]

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.