I have a table which has a field isClaimed that has only two fixed values = CLAIMED or NOT CLAIMED. I have to calculate the total of each field.
FYI, assume this is my table:
name | isClaimed  
Aye  | NOT CLAIMED 
Ian  | CLAIMED  
Jan  | NOT CLAIMED  
Zen  | NOT CLAIMED  
Pom  | CLAIMED  
Total of unclaimed: 3
Total of claimed: 2
And please check my code below:
<?php 
 $sql = "SELECT pro.ScholarId, pro.Lastname, pro.Middlename, pro.Firstname, pro.Address, levels.LevelName, school.SchoolName, barangays.BarangayName, payroll.Allowance, sp.Points, pro.ScholarPointId, sca.isClaimed
FROM scholar_profile as pro 
JOIN scholar_school as school ON pro.SchoolId = school.SchoolId
JOIN levels ON pro.LevelId = levels.LevelId
JOIN barangays ON pro.BarangayId = barangays.BarangayId
JOIN payroll ON payroll.PayrollId = levels.PayrollId
INNER JOIN scholar_points as sp ON pro.ScholarPointId = sp.ScholarPointId
JOIN scholar_claim_allowance as sca ON pro.ScholarId = sca.ScholarId 
ORDER BY pro.LevelId, pro.ScholarId";
// OREDER BY id DESC is order result by descending
$result2 = mysql_query($sql);  
if($result2 === FALSE) {
die(mysql_error()); // TODO: better error handling
} 
// Start looping table row
while ($row2 = mysql_fetch_array($result2)) {
    $firstname = $row2["Firstname"];
    $lastname = $row2["Lastname"];
    $middlename = $row2["Middlename"];
    $barangay = $row2["BarangayName"];
    $level = $row2["LevelName"];
    $allowance = $row2["Allowance"];
    $isClaimed = $row2["isClaimed"];
?>
<tr>
<td class="spec"><?php echo $lastname.", ".$firstname. " " .substr($middlename, 0,1) . "." ; ?>   </td>
<td><?php echo $barangay; ?></td>
<td><?php echo $level; ?></td>
<td><?php echo $allowance; ?></td>
<td><?php echo $isClaimed ?></td>
</tr>
<?php
// Exit looping
}
?>
<tr>
<td colspan="4" class="spec">Total of unclaimed allowances</td>
<td></td>
 </tr>
<tr>
<td colspan="4" class="spec">Total of claimed allowances</td>
<td></td>
</tr>
I have tried the tutorial from here: http://www.randomsnippets.com/2008/10/05/how-to-count-values-with-mysql-queries/ But i can't get it to work in php.
 
     
    