Jump to content

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


SciFiSi

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.

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.

.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.