Search code examples
phpmysqltime-and-attendance

How to check best-attending employees of the year


This is my MySQL table:

_______________________________________________
Id | Name| Employee id | Date       | Attendance
_______________________________________________
1  | xyz |     196     | 2013-04-01 | present  
2  | xyz |     196     | 2013-04-02 | present  
3  | xyz |     196     | 2013-04-03 | present  
4  | xyz |     196     | 2013-04-04 | absent  
5  | xyz |     196     | 2013-04-05 | present  
6  | abc |     197     | 2013-04-01 | present

7  | abc |     197     | 2013-04-02 | present  
8  | abc |     197     | 2013-04-03 | present  
9  | abc |     197     | 2013-04-04 | present  
10 | abc |     197     | 2013-04-05 | present

_______________________________________________

I want to count a days who employee are mostly present, and I want like this result in PHP:

___________________________________________________________
 Name| Employee id| Attendance     | Best OR NOT
___________________________________________________________
 xyz |  196       | 4 Present days |

 abc |  197       | 5 Present days | This is best employees of the year

__________________________________________________________________________

How can i do this?


Solution

  • Try this.

       $query = mysql_query("select name ,`Employee id` as emplyee_id, CONCAT(count(`Employee id`),' Present days') as Attendance
       from Table1 
       where `Attendance` = 'present' group by `Employee id` ");
    
    
    
       while($row = mysql_fetch_array($query)) {
      echo $row['name']. " - " .$row['emplyee_id']. " - " .$row['Attendance']."</ br>";
     }
    

    DEMO HERE