Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9089009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T22:02:25+00:00 2026-06-16T22:02:25+00:00

I have a table which has a field isClaimed that has only two fixed

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T22:02:26+00:00Added an answer on June 16, 2026 at 10:02 pm

    From the tutorial you linked….

    $sql = "SELECT
    SUM(IF(sca.isClaimed = "CLAIMED", 1,0)) AS claimedTotal,
    SUM(IF(sca.isClaimed = "NOT CLAIMED", 1,0)) AS notClaimedTotal,
    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";
    

    And then

    echo $row2["claimedTotal"];
    

    and

    echo $row2["notClaimedTotal"];
    

    Note that I used the table sca for for the isClaimed value, just a guess…not sure of your table structure, maybe you will need to change sca to reflect the correct table.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table which has a field called Sold , in that field
I have an SQL Server 2005 table that has a varchar(250) field which contains
I have a Table which has a Primary Key field which is not set
i have these tables /entities VacationRequestDate table which has a VacationRequestId field that links
I have a SQL SERVER Table which has only one field StartDate the records
Suppose I have table tags which has a field count that indicates how many
I have a table which has only one number field: [ value NUMBER(12.0) ]
I have a groups table which has a field called permissions that has a
I have a table called SharedNumber , which has only one field - an
I have requirement like, suppose I have a 'property' table which has 'ListingKey' field

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.