gpt4 book ai didi

php - 按时间段显示菜单 PHP PHP MySQL

转载 作者:行者123 更新时间:2023-11-29 12:25:39 26 4
gpt4 key购买 nike

我在 MySQL 数据库中有一个表,其中存储餐厅在每个工作日和时段提供的菜单。

表结构如下:

i_type      i_name    i_cost   i_day   i_start     i_end
--------------------------------------------------------
Breakfast Prantha 20 0 07:00 11:00
Lunch Special 80 0 11:01 15:00
Dinner Special 100 0 15:01 21:00

其中 0 = 星期日,依此类推。

例如早餐(07:00至11:00)、午餐(11:01至15:00)

现在,一周中的每一天的菜单都显示得非常好。但我希望按照以下方法显示菜单:

  1. 如果客户在早上(即早餐时间或更早)进入餐厅,则应允许他订购早餐、午餐和晚餐。
  2. 如果客户在午餐时间进入餐厅,则只能订购午餐和晚餐,而不能订购早餐。

为了获取星期几,我使用以下方法

$jd=cal_to_jd(CAL_GREGORIAN,date("m"),date("d"),date("Y"));
$dw = (jddayofweek($jd,0));

目前我正在处理如下时间段:

$datr = (int)date('Hi');
$timew= str_replace(':', '', $row['i_start']); $timec= str_replace(':', '',
$row['i_end']);
if (($datr < $timew) || ($datr > $timec)) { ?>
<button class="btn btn-default" style="background:#ED3E49;border-color:
#E31522;color:#fff;padding:5px;border-radius:5px" disabled="disabled">
&nbsp;Ordering Closed</button> } ?>

但是上述方法不允许我在早餐时间点午餐等等。

最佳答案

试试这个:

    $dayValueFromDB = $row['i_day'];
$jd=cal_to_jd(CAL_GREGORIAN,date("m"),date("d"),date("Y"));
$currentDayValue = (jddayofweek($jd,0));
//for just today and tomorrow the last condition in if is for the senario if today in saturday and tomorrow is sunday
if($dayValueFromDB == $currentDayValue || $dayValueFromDB == ($currentDayValue+1) || ($dayValueFromDB == 0 && $currentDayValue==6))
if ($datr > $timec){
//your code
}
}
else{
//for all other days display no order will be taken or whatever you like
}

关于php - 按时间段显示菜单 PHP PHP MySQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28358703/

26 4 0