大家晚上,
我是公园,现在我正在为我的小企业做系统。
$query = "SELECT empid, count(t_status)FROM timesheet WHERE t_status = 'Full Day' group by empid";
$result = mysql_query($query)or die (mysql_error());
print "<table\">
<tr>
<th>ID</th>
<th>Total.Full</th>
<th>Total.Half</a></th>
<th>Totah.Off</a></th>
<th>Options</a></th>
</tr>";
while ($row = mysql_fetch_array($result)){
print "<tr>";
print "<td>" . $row['empid']. "</td>";
print "<td>" . $row['count(t_status)']. "</td>";
print "<td>" . $row['HERE FOR HALF DAY TOTAL']. "</td>";
print "<td>" . $row['HERE FOR OFF DAY TOTAL']. "</td>";
print "</tr>";}
print "</table>";
==============================
所以,我如何检索工作日和半日总计将其显示在“全天”的下一栏中。
不建议“PDO”或“MYSQLI”,因为我将在未来详细介绍.TQ。
答案 0 :(得分:0)
$query = "SELECT empid, SUM(IF(t_status='Full Day',1,0)) as full_day,
SUM(IF(t_status='Half Day',1,0)) as half_day,
SUM(IF(t_status='Off Day',1,0)) as off_day
FROM timesheet GROUP BY empid";
$result = mysql_query($query)or die (mysql_error());
print "<table>
<tr>
<th>ID</th>
<th>Total.Full</th>
<th>Total.Half</a></th>
<th>Totah.Off</a></th>
<th>Options</a></th>
</tr>";
while ($row = mysql_fetch_array($result)){
print "<tr>";
print "<td>" . $row['empid']. "</td>";
print "<td>" . $row['full_day']. "</td>";
print "<td>" . $row['half_day']. "</td>";
print "<td>" . $row['off_day']. "</td>";
print "</tr>";
}
print "</table>";