Jump to content

The easiest code in the world and yet it doesn't work - WTF!?


Go to solution Solved by _EmilsM,

Recommended Posts

This should be the easiest thing in the world, but it just does not and WILL not work. I've spent hours and hours on this and I just do NOT understand what's wrong with this code can someone - anyone please please help and explain what I'm doing wrong!?

$hour = date('G');
echo "$hour ";

if ($hour >= 0 && $hour <= 11)
{
 echo 'Good morning ';
}
else if ($hour >=12 && $hour <=17)
{
 echo 'Good afternoon ';
}
else ($hour >=18)
{
 echo 'Good evening ';
}

All it ever prints out is Good evening! WTF!

<?php

$hour = date('G');

echo "$hour ";

 

if ($hour >= 0 && $hour <= 11)

{

 echo 'Good morning ';

}

else if ($hour >=12 && $hour <=17)

{

 echo 'Good afternoon ';

}

else if($hour >=18 && $hour<= 24)

{

 echo 'Good evening ';

}

?>

 

using this, prints good afternoon.

 

EDIT. Maybe because $hour is now 18 to 24 for you. Define $hour for yourself, try 0, 11, 12, 17 and you'll see that it changes.

Edited by _EmilsM

Ah, yes I see you added the <=24.

 

I've copied and pasted your code and now I don't get any output at all. What is probably VERY worth mentioning is that I'm using a plugin for Wordpress

; http://wordpress.org/plugins/allow-php-in-posts-and-pages/

 

It's very possible that this plugin just doesn't work and if that's the case I'll be peeved.

.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.