shazly Posted May 18, 2006 Share Posted May 18, 2006 i have this table "my_points" in my database. it has two cloumns, 1- points_id2- pointsi have 20 entries in this table, in the second col. i have numbers in each entry (just plain numbers), i.e 232now 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 https://forums.phpfreaks.com/topic/9908-how-to-calculate-numbers-in-a-certain-column/ Share on other sites More sharing options...
.josh Posted May 18, 2006 Share Posted May 18, 2006 $result = mysql_query("SELECT count(points) as total FROM my_points");$totalpoints = mysql_fetch_array($result);echo $totalpoints['total']; Link to comment https://forums.phpfreaks.com/topic/9908-how-to-calculate-numbers-in-a-certain-column/#findComment-36822 Share on other sites More sharing options...
Barand Posted May 18, 2006 Share Posted May 18, 2006 [!--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 https://forums.phpfreaks.com/topic/9908-how-to-calculate-numbers-in-a-certain-column/#findComment-36835 Share on other sites More sharing options...
shazly Posted May 18, 2006 Author Share Posted May 18, 2006 thanks alot barand and Crayon Violet Link to comment https://forums.phpfreaks.com/topic/9908-how-to-calculate-numbers-in-a-certain-column/#findComment-36865 Share on other sites More sharing options...
.josh Posted May 18, 2006 Share Posted May 18, 2006 oops i really meant sum thx barand Link to comment https://forums.phpfreaks.com/topic/9908-how-to-calculate-numbers-in-a-certain-column/#findComment-36979 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.