Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

i am developing a blood bank management system. Now i want to display that how many times each user donated blood, i mean i want to get the sum of each user row. For example if a donor(who's passport/IC is AF3444547)has 3 row in the database so i need show the total row from the database.If next time i put another record of AF3444547 then i need to get the sum 4. The image shown in below of my databse. Thanks in advance blood donation record

Here is my code

 <?php
                    $passport_IC='passport_IC';
                      $q="SELECT passport_IC, count(*) FROM donate GROUP BY passport_IC";
                      $query=$db->prepare($q);

                      $query->execute(array($passport_IC));
                      $people = $query->fetchAll(PDO::FETCH_OBJ);


                    ?>
     <table class="table table-bordered">
      <tr>
        <th><center> passport </center></th>
        <th><center> quantity</center></th>




      </tr>
      <?php foreach($people as $donors): ?>
        <tr>
           <td><center><b><font color="white"><?= $donors->passport_IC; ?></font></b></center></td>




        </tr>
      <?php endforeach; ?>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
228 views
Welcome To Ask or Share your Answers For Others

1 Answer

Is not sum() what you need...

count(*) is the answer.

The COUNT (*) function returns the number of rows that satisfy the WHERE clause of a SELECT statement.

https://www.ibm.com/support/knowledgecenter/en/SSGU8G_12.1.0/com.ibm.sqls.doc/ids_sqs_1580.htm

 $q=$db->query("SELECT COUNT(*) from donate WHERE passport_ic=:passport_ic" );

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...