Jump to content

Archived

This topic is now archived and is closed to further replies.

shazly

How to calculate numbers in a certain column

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]

Share this post


Link to post
Share on other sites
$result = mysql_query("SELECT count(points) as total FROM my_points");
$totalpoints = mysql_fetch_array($result);
echo $totalpoints['total'];

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

×

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.