I have two tables one have employee name, employee id and another one is tblleaves have empid,Leave_Date, fromDate, toDate, Description.
If employee choose one date leave it stores the date value to Leave_Date and if employee choose multiple dates it store value of from date and to date.
The output page I want an employee name, Leave Days and Leave Dates. Leave Dates have dates from Leave_date, FromDate and ToDate.
<?php
if(isset($_POST['apply'])){
$ym=$_POST['month'];
list($Year, $Month) = explode("-", "$ym", 2);
$sql = "SELECT
tblemployees.FirstName,
tblemployees.LastName,
count(tblleaves.empid) as Leave_Days,
GROUP_CONCAT( tblleaves.Leave_Date SEPARATOR ', ' ) AS leave_dates
FROM
tblleaves
JOIN tblemployees
ON tblleaves.empid = tblemployees.id
WHERE YEAR(Leave_Date) = $Year
AND MONTH(Leave_Date) = $Month
GROUP BY tblemployees.EmpId";
$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 echo htmlentities($result->Leave_Days);
?></td>
<td><?php echo htmlentities($result->leave_dates);
?></td><?php $cnt++;}}}?>
</tr>
</tbody>
</table>
The output i want:
employee name Leave Days Leave Dates
KrishnanR 3 12-06-2019, 13-06-2019, 14-06-2019
(FromDate and ToDate)
PrakashR 1 12-06-2019
(Leave_Date)
SelvaK 3 12-06-2019,13-06-2019&14-06-2019|14-06-2019
(FromDate and ToDate) (Leave_Date)