I have a table to store talent leave its structure is like this
table:talent_leave
id talent from_date to_date
1 10 2016-09-02 2016-09-04
This entry means that He applied for a leave for 2016-09-02 to 2016-09-04. What I need is to display this days status when he try to apply another from and to date which has one of these dates[2016-09-02 , 2016-09-03 , 2016-09-04]
Eg:If he apply 2016-09-04 to 2016-09-06
My Application Should show
2016-09-04 / Planned Leave
2016-09-05 / Not Planned
2016-09-06 / Not Planned
I have a solution in PHP but it is very slow The solution i Found is
$plannedLeaveArray=array();
$sql="select from_date and to_date From talent_leave Where talent=10";
$result=mysql_query($sql);
while($row=mysql_fetch_array($result)){
$from_date=$row['from_date'];
$to_date=$row['to_date'];
while (strtotime($to_date) >= strtotime($from_date)) {
$plannedLeaveArray[] = $from_date;
$from_date = strtotime("+1 day", strtotime($from_date));
}
}
Now i get the planned date in array
$from_post=$_POST['from'];
$to_post=$_POST['to'];
while (strtotime($to_post) >= strtotime($from_post)) {
if (in_array($from_post, $plannedLeaveArray)) {
echo $from_post."/".Planned Leave
}else{
echo $from_post."/".Not Planned
}
$from_post= strtotime("+1 day", strtotime($from_post));
}
It takes too much time to load.If you people have a better solution or suggestion that would be great.