Reputation: 318
I have 3 array in my database that is coming from a form a form
array result form database
I would like to check if the current date is in the range of the two arrays and if there is a match display the name of he staff member from the staff array for example if I take only the first value of each array the result will be
This is what I tried but that doesn't give me the proper result :
$neword = "SELECT `order_id` , `item`,`staff_name`, `staff_start_d`,`staff_end_d`,`item_sn`,`status`, DATE_FORMAT(`stamp` , '%d-%m-%Y' ) as `stamp` FROM rent ";
$userord = mysqli_query($link, $neword);
foreach ($userord as $myitem);
<?php foreach ($userord as $myitem) : ?>
<?php
$s_dates = array($myitem['staff_start_d']);
$e_dates = array($myitem['staff_end_d']);
$names = array($myitem['staff_name']);
$start = date("Y-m-d");
foreach($s_dates AS $date_s) {
$timestamp = strtotime($date_s);
if($timestamp == $start ) {
echo "1";
}else{
echo "no1";
}
}
foreach($e_dates AS $date_e) {
$timestamp = strtotime($date_e);
if($timestamp == $start ) {
echo "2";
}else{
echo 'no2';
}
}
?>
Upvotes: 0
Views: 49
Reputation: 2104
You need to convert date in timestamp and then you can check as below code:
$s_dates = explode(",", $myitem['staff_start_d']);
$e_dates = explode(",",$myitem['staff_end_d']);
$names = explode(",", $myitem['staff_name']);
$start = date("Y-m-d");
foreach($s_dates as $key => $date_s) {
if (strtotime($start) >= strtotime($date_s) && strtotime($start) <= strtotime($e_dates[$key])) {
// show your employee details here as
echo $date_s.'<br/>';
echo $e_dates[$key].'<br/>';
echo $names[$key].'<br/>';
}
}
Also, I am assuming that you are making value array which is useless. Hope it helps you.
Upvotes: 1