Page 1 of 1

count total of ....

Posted: Sun Nov 13, 2005 4:58 pm
by blacksnday
How can I count total value of a certain row in a field?

Table: Test
Field: access attempts

where row for access attempts would be any number from 0 - 1000
and I need to count total value of all rows with a value in access attempts

Posted: Sun Nov 13, 2005 5:35 pm
by RobertPaul
SELECT SUM(access attempts) AS total_attempts FROM Test

Posted: Sun Nov 13, 2005 5:37 pm
by RobertGonzalez
You can use either array_sum() or you can loop through the result set and add each value by concatenating.

Code: Select all

<?php
while ( $row = mysql_fetch_array($result) )
{
    $row_total += $row['access_attempts'];
}

Posted: Sun Nov 13, 2005 5:45 pm
by blacksnday
Thanks for the advice from both of ya's :)