<table id="datatable-1" class="table table-striped table-hover">
<thead>
<tr align="center" class="h4">
<th>#</th>
<th>วิชาชีพ</th>
<th>2550</th>
<th>2551</th>
<th>2552</th>
<th>2553</th>
<th>2554</th>
<th>2555</th>
<th>2556</th>
<th>2557</th>
<th>2558</th>
<th>2559</th>
<th>รวม</th>
</tr>
</thead>
<tbody>
<?
include ("conn.php");
$select_data=$mysqli->query("SELECT * FROM position");
$num_p=$select_data->num_rows;
$i=1;
while ($row_data=$select_data->fetch_assoc()){
$d_date=$row_data[datework];
//
$name1A1=$mysqli->query("SELECT count(*) as num101 FROM staff WHERE pos_id='$row_data[position_id]'
and pos_type!=101 and datework like '2007%' ");
$row_data1=$name1A1->fetch_assoc();
//
$name2A2=$mysqli->query("SELECT count(*) as num102 FROM staff WHERE pos_id='$row_data[position_id]'
and pos_type!=101 and datework like '2008%' ");
$row_data2=$name2A2->fetch_assoc();
//
$name3A3=$mysqli->query("SELECT count(*) as num103 FROM staff WHERE pos_id='$row_data[position_id]'
and pos_type!=101 and datework like '2009%'");
$row_data3=$name3A3->fetch_assoc();
//
$name4A4=$mysqli->query("SELECT count(*) as num104 FROM staff WHERE pos_id='$row_data[position_id]'
and pos_type!=101 and datework like '2010%' ");
$row_data4=$name4A4->fetch_assoc();
//
$name5A5=$mysqli->query("SELECT count(*) as num105 FROM staff WHERE pos_id='$row_data[position_id]'
and pos_type!=101 and datework like '2011%' ");
$row_data5=$name5A5->fetch_assoc();
//
$name6A6=$mysqli->query("SELECT count(*) as num106 FROM staff WHERE pos_id='$row_data[position_id]'
and pos_type!=101 and datework like '2012%'");
$row_data6=$name6A6->fetch_assoc();
//
$name7A7=$mysqli->query("SELECT count(*) as num107 FROM staff WHERE pos_id='$row_data[position_id]'
and pos_type!=101 and datework like '2013%'");
$row_data7=$name7A7->fetch_assoc();
//
$name8A8=$mysqli->query("SELECT count(*) as num108 FROM staff WHERE pos_id='$row_data[position_id]'
and pos_type!=101 and datework like '2014%'");
$row_data8=$name8A8->fetch_assoc();
//
$name9A9=$mysqli->query("SELECT count(*) as num109 FROM staff WHERE pos_id='$row_data[position_id]'
and pos_type!=101 and datework like '2015%'");
$row_data9=$name9A9->fetch_assoc();
//
$name10A10=$mysqli->query("SELECT count(*) as num110 FROM staff WHERE pos_id='$row_data[position_id]'
and pos_type!=101 and datework like '2016%'");
$row_data10=$name10A10->fetch_assoc();
//
$name10A11=$mysqli->query("SELECT count(*) as num111 FROM staff WHERE pos_id='$row_data[position_id]'
and pos_type!=101 ");
$row_data11=$name10A11->fetch_assoc();
//
?>
<tr class="h5">
<td valign="top"><?=$i;?></td>
<td ><a href="position.php?p_code=<?=$row_data[position_id]?>">
<?=$row_data[position_name]?>
</a></td>
<td alig="center"><? echo"$row_data1[num101]";?></td>
<td><? echo"$row_data2[num102]";?></td>
<td><? echo"$row_data3[num103]";?></td>
<td><? echo"$row_data4[num104]";?></td>
<td><? echo"$row_data5[num105]";?></td>
<td><? echo"$row_data6[num106]";?></td>
<td><? echo"$row_data7[num107]";?></td>
<td><? echo"$row_data8[num108]";?></td>
<td><? echo"$row_data9[num109]";?></td>
<td><? echo"$row_data10[num110]";?></td>
<td><? echo"$row_data11[num111]";?></td>
</tr>
<? $i++; }?>
<tr class="h5">
<td valign="top"> </td>
<td>รวม</td>
<td bgcolor="#FFCC33" alig="center"><?
$numT1=$mysqli->query("SELECT count(*) as numt1 FROM staff WHERE datework like '2007%' and pos_type!=101");
$row_t1=$numT1->fetch_assoc();
echo"$row_t1[numt1]";
?></td>
<td bgcolor="#FFCC33"><?
$numT2=$mysqli->query("SELECT count(*) as numt2 FROM staff WHERE datework like '2008%' and pos_type!=101");
$row_t2=$numT2->fetch_assoc();
echo"$row_t2[numt2]";
?></td>
<td bgcolor="#FFCC33"><?
$numT3=$mysqli->query("SELECT count(*) as numt3 FROM staff WHERE datework like '2009%' and pos_type!=101");
$row_t3=$numT3->fetch_assoc();
echo"$row_t3[numt3]";
?></td>
<td bgcolor="#FFCC33"><?
$numT4=$mysqli->query("SELECT count(*) as numt4 FROM staff WHERE datework like '2010%' and pos_type!=101");
$row_t4=$numT4->fetch_assoc();
echo"$row_t4[numt4]";
?></td>
<td bgcolor="#FFCC33"><?
$numT5=$mysqli->query("SELECT count(*) as numt5 FROM staff WHERE datework like '2011%' and pos_type!=101");
$row_t5=$numT5->fetch_assoc();
echo"$row_t5[numt5]";
?></td>
<td bgcolor="#FFCC33"><?
$numT6=$mysqli->query("SELECT count(*) as numt6 FROM staff WHERE datework like '2012%' and pos_type!=101");
$row_t6=$numT6->fetch_assoc();
echo"$row_t6[numt6]";
?></td>
<td bgcolor="#FFCC33"><?
$numT7=$mysqli->query("SELECT count(*) as numt7 FROM staff WHERE datework like '2013%' and pos_type!=101");
$row_t7=$numT7->fetch_assoc();
echo"$row_t7[numt7]";
?></td>
<td bgcolor="#FFCC33"><?
$numT8=$mysqli->query("SELECT count(*) as numt8 FROM staff WHERE datework like '2014%' and pos_type!=101");
$row_t8=$numT8->fetch_assoc();
echo"$row_t8[numt8]";
?></td>
<td bgcolor="#FFCC33"><?
$numT9=$mysqli->query("SELECT count(*) as numt9 FROM staff WHERE datework like '2015%' and pos_type!=101");
$row_t9=$numT9->fetch_assoc();
echo"$row_t9[numt9]";
?></td>
<td bgcolor="#FFCC33"><?
$numT10=$mysqli->query("SELECT count(*) as numt10 FROM staff WHERE datework like '2016%' and pos_type!=101");
$row_t10=$numT10->fetch_assoc();
echo"$row_t10[numt10]";
?></td>
<td bgcolor="#FFCC33"><?
$numT11=$mysqli->query("SELECT count(*) as numt11 FROM staff WHERE pos_type!=101");
$row_t11=$numT11->fetch_assoc();
echo "$row_t11[numt11]";?></td>
</tr>
</tbody>
</table>
select sum( if(year(datework)=2014, 1, 0)) as y2014
, sum( if(year(datework)=2015, 1, 0)) as y2015
, sum( if(year(datework)=2016, 1, 0)) as y2016
from table where ......