我的数据库中有3个数组,这些数组来自表单
数组结果表单数据库
我想检查当前日期是否在两个数组的范围内,并且是否有匹配的显示,显示职员列表中职员的姓名 例如,如果我只取每个数组的第一个值,结果将是
这是我尝试过的方法,但没有给我适当的结果:
$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';
}
}
?>
答案 0 :(得分:1)
您需要在时间戳中转换日期,然后可以检查以下代码:
$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/>';
}
}
此外,我假设您正在创建没有用的值数组。希望对您有帮助。