Question: How can I calculate all fields in a while? Example: I have a while, those has four rows. Every row had a specific number. What I want is, what is the total of the numbers same?

```
while ($row= mysql_fetch_assoc($select)) {
echo $row['persons'];
}

```

Persons is for how many people there are in a group. I want all people in the four rows total, like this.

```
$row['persons'](5) + 
$row['persons'](6) +
$row['persons'](3) +
$row['persons'](3) = 17

```

(x) means how many people are in the field. How can I calculate this in a while, so my `echo` is: just 17.

Answer: 
try this code Please using SUM Function 

```
$result = mysql_query("SELECT SUM(persons) AS personCount  FROM tableName");

if (!$result) {
echo 'Could not run query: ' . mysql_error();
exit;

}

$row = mysql_fetch_row($result);

echo $row[0];

```
If I get you right, you want to sum up all the numbers in `persons` column.

```
$count = 0;
while ($row= mysql_fetch_assoc($select)) {
    $count += $row['persons'];
}
echo $count;

```

Better way, though, is to use [`SUM()`](http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html#function_sum) aggregate built-in function of MySQL.