开发者

1) Displaying Text between Certain Times 2) Adding a "Time Recieved" Field on a Form

开发者 https://www.devze.com 2023-03-18 18:21 出处:网络
2 PHP related questions here I th开发者_C百科ink: 1) Is it possible to use PHP to display a line of text between certain times, so for example, I might want to display\"Good Morning\" between 5am and

2 PHP related questions here I th开发者_C百科ink:

1) Is it possible to use PHP to display a line of text between certain times, so for example, I might want to display "Good Morning" between 5am and 12pm PST, "Good Afternoon" between 12:01pm and 4:59pm PST, "Good Evening" between "5:00pm and 9:00pm" and "Good Night" from 9:00pm until 4:59am PST.

If this is possible, what would the PHP look like?

2) I have a simple HTML form that posts its result into a database table. Is it possible to add a hidden field somewhere that notes the DATE and TIME the data entry was added to the database? If so, what would I add to my form and database?


You can just use an if-else statement to display certain text.

$current_hour = intval(date('H'));

if ( $current_hour < 12 )
{
    echo "Good Morning";
}
else if ( $current_hour < 17 )
{
    echo "Good Afternoon";
}
else
{
    echo "Good evening";
}

As for the HTML form, you'd be better off not having a hidden field, rather including the date from the page that processes the SQL statement.

http://php.net/manual/en/function.date.php will help you format the date. Just format the date how you want it, and then include it in the SQL query.

0

精彩评论

暂无评论...
验证码 换一张
取 消