firedealer Posted April 28, 2010 Share Posted April 28, 2010 index.php?time=dark won't get the dark hour result from $_GET and operators or vice versa. What went wrong with this? $current_time = date(G); // light hours if (($_GET['time'] == "light") || ($current_time >= 5 && $current_time <= 19)) { echo "Light hours"; // dark hours } elseif (($_GET['time'] == "dark") || ($current_time >= 20 && $current_time <= 23) || ($current_time >= 0 && $current_time <= 4)) { echo "Dark hours"; } Link to comment https://forums.phpfreaks.com/topic/200087-_get-from-url-logical-operator-problem/ Share on other sites More sharing options...
jdavidbakr Posted April 28, 2010 Share Posted April 28, 2010 So are you getting nothing or are you getting the wrong result? Try adding echo $_GET['time'] to the top to make sure you really are getting passed what you think you're getting passed. You might also try removing the second condition (checking $current_time) to make sure that it is indeed the $_GET condition that's breaking your logic. Link to comment https://forums.phpfreaks.com/topic/200087-_get-from-url-logical-operator-problem/#findComment-1050182 Share on other sites More sharing options...
Mchl Posted April 28, 2010 Share Posted April 28, 2010 That's because if condition for "light hours" is evalueated true, the condition for "dark hours" will not be evaluated at all. Try like this: if(isset($_GET['time'])) { if($_GET['time'] == 'light') { $hours = 'Light'; } elseif ($_GET['time'] == 'dark') { $hours = 'Dark'; } else { $hours = null; } } if(!isset($hours)) { $current_time = date('G'); if ($current_time >= 5 && $current_time <= 19) { $hours = 'Light'; } else { $hours = 'Dark'; } } echo "$hours hours"; Link to comment https://forums.phpfreaks.com/topic/200087-_get-from-url-logical-operator-problem/#findComment-1050183 Share on other sites More sharing options...
firedealer Posted April 28, 2010 Author Share Posted April 28, 2010 Mchl, thanks! That solved my problem. Link to comment https://forums.phpfreaks.com/topic/200087-_get-from-url-logical-operator-problem/#findComment-1050195 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.