【发布时间】:2019-06-08 12:07:23
【问题描述】:
我有两个表,一个有员工姓名、员工 ID,另一个有 empid、Leave_Date、fromDate、toDate、Description 的表 tblleaves。
如果用户选择一天休假,则将日期值存储到 Leave_Date,如果用户选择多天,则存储从日期到日期的值。
现在我想要员工的月度报告。在此页面中,我想要员工姓名、休假天数和休假日期。我尝试了代码,但我反复得到员工姓名,因为他们在那个月申请了很多假,我想一次显示员工姓名。
<?php
if(isset($_POST['apply'])){
$ym=$_POST['month'];
list($Year, $Month) = explode("-", "$ym", 2);
$sql = "SELECT distinct tblleaves.id as lid,tblemployees.FirstName,tblemployees.LastName,tblemployees.EmpId,
tblemployees.id,tblleaves.LeaveType,tblleaves.PostingDate,
tblleaves.Leave_Date from tblleaves join tblemployees on tblleaves.empid=tblemployees.id
WHERE YEAR(Leave_Date) = 2019 AND MONTH(Leave_Date) = 6";
echo $sql;
$query = $dbh -> prepare($sql);
$query->execute();
$results=$query->fetchAll(PDO::FETCH_OBJ);
$cnt=1;
if($query->rowCount() > 0)
{
foreach($results as $result)
{ ?>
<tr>
<td> <?php echo htmlentities($cnt);?></td>
<td><?php echo htmlentities($result->FirstName);?> <?php echo htmlentities($result->LastName);?></td>
<td><?php ?></td>
<td><?php $result->Leave_Date?></td>
<?php $cnt++;}}}?>
我想要员工月假报告
employee name Leave Days Leave Dates
KrishnanR 3 12-06-2019, 13-06-2019, 14-06-2019
【问题讨论】: