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] Quote 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']; Quote 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. Quote 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 Quote 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 Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.