pthes Posted April 17, 2007 Share Posted April 17, 2007 I have come across the strangest error in one of my sites today. I checking to see what hour of the day it is and then use it as the default value of a dropdown box. The problem is that if the hour is "08" or "09" the value gets set to "00". I created simple code to test. <?php $val = 01; ?> <?php if ($val == 01) { echo $val." what is this!!";} else {echo "should be 1";} ?> <?php $val = 02; ?> <?php if ($val == 02) { echo $val." what is this!!";} else {echo "should be 2";} ?> <?php $val = 08; ?> <?php if ($val == 08){ echo $val." what is this!!";} else {echo "should be 8";} ?> <?php $val = 09; ?> <?php if ($val == 09) { echo $val." what is this!!";} else {echo "should be 9";} ?> This is what I get 1 what is this!! 2 what is this!! 0 what is this!! 0 what is this!! It looks like when $val == 08 is executed it sets $val to 0 !! I'm using PHP 5 If anyone has seen this before please let me know what's going on. Thanks. Quote Link to comment Share on other sites More sharing options...
Psycho Posted April 17, 2007 Share Posted April 17, 2007 Um, why do you enclose each line in it's own script tags? Concerning your problem, 01, 02, 03 are not numbers. 1, 2, 3 are numbers. You either need to test using strings or use real numbers Quote Link to comment Share on other sites More sharing options...
pthes Posted April 17, 2007 Author Share Posted April 17, 2007 Tagged like that because of quick copy and paste to create the script. As for 01,02,03 not being numbers, that how it comes out of date/time field in mySQL. Also, if they're not numbers why does it work perfectly for all numbers from 00 to 23 except for 08 and 09? Quote Link to comment Share on other sites More sharing options...
Hughesy1986 Posted April 17, 2007 Share Posted April 17, 2007 Wow that is strange lol, I just run it and got the same result. If i take away the 0 before the number it works. Glen Quote Link to comment Share on other sites More sharing options...
pthes Posted April 17, 2007 Author Share Posted April 17, 2007 I wonder if it's a PHP 5 thing. Which version are you running? Peter. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.