(PHP) 仅在工作时间显示链接?

编程入门 行业动态 更新时间:2024-10-25 00:28:56
本文介绍了(PHP) 仅在工作时间显示链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我试图在网站上在工作时间内显示实时聊天链接.我有下面的代码,它似乎在下午工作,但在早上不起作用,我不知道为什么...... $start$end是从 MySQL 数据库接收的值,但在我的示例中,我对它们进行了硬编码以使示例更简单.

I am trying to make a live chat link appear on the website only during business hours. I have the code below which seems to work in the afternoon, but won't work in the morning and I'm not sure why... $start and $end are values received from a MySQL database but in my example I've hard coded them to make the example simpler.

$LinkStatus = "on";

$start = 9:00:00;
$end = 23:00:00;
$current_time = date('G:i:s'); //9:35:00

if (($start > $current_time) || ($end < $current_time)) {
    $LinkStatus = "off"; 
}

如果开始时间大于当前时间,则该业务尚未开放.如果结束时间小于当前时间,则为小时后.在上午 9 点到晚上 11 点(23:00)之间的任何时间,这些条件都不应该为真,因此 $LinkStatus 应该保持 "on".但是,它现在似乎没有这样做.有些东西将它设置为 "off".

If the start time is greater than the current time, then the business is not open yet. If the end time is less than the current time, then it's after hours. Any time between 9am and 11pm (23:00) neither one of those conditions should be true, therefore $LinkStatus should remain "on". However, it does not seem to be doing that right now. Something is setting it to "off".

我已经在 if 语句上方和下方回显了变量,所以我可以确认是这个 if 语句导致变量被设置为 "off".

I've echoed the variable above the if statement and below it so I can confirm it's this if statement causing the variable to be set to "off".

正如您可能从我的代码示例中看到的,我对 PHP 不是很了解.任何帮助表示赞赏.

As you can probably see from my code example, I'm not very knowledgeable when it comes to PHP. Any help is appreciated.

推荐答案

date('G:i:s')  // 24 hours time without leading zero for hour

...不会像字符串那样排序,例如 '9' > '10'.

...won't sort well as a string, for example '9' > '10'.

改为使用 24 小时制,并带有前导零,这使得正确的排序为 '09' <'10';

Use 24 hour time with a leading zero instead, which makes the correct sort '09' < '10';

date('H:i:s')  // 24 hour time with leading zero for hour

这篇关于(PHP) 仅在工作时间显示链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-30 12:40:56,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1393543.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:工作时间   链接   PHP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!