Hello!
For more debugging, you can try printing exactly the _expression_ result instead of separate variables.
For example, before the actual comparison:
print ($cur_time - $updated_time) . ' <= 86400';
Then, right at the start of the if's "true" branch, add additional
print "if was true";
To be sure whether you got into if's body or not. I suppose your current print statement within the if does not have the syntax error as in the example you sent here, but in some cases you may not recognize that you actually got inside the if all right.
Regards,
Janis
No: Steve Matzura <sm@xxxxxxxxxxxxxx>
Nosūtīts: otrdiena, 2024. gada 8. oktobris 04:01 Kam: php-general@xxxxxxxxxxxxx <php-general@xxxxxxxxxxxxx> Tēma: Comparing Two Numbers Fails In a script, I am testing two values--$cur_time and $updated_time, and if their difference is less than or equal to 86400, some processing is supposed to occur. Just before the test, I have a print statement which displays the values needed for the if test to succeed, followed by the if test, followed by what to do if the test succeeds, starting with another print statement, which is supposed to show me on-screen that the test succeeds and I'm now into the processing code.
*** Snip ***
$x = ($cur_time - $updated_time); // Don't worry, those variables really do exist. print "$showcode, $cur_time, $updated_time, $x\n"; // Display the variables in question before the test. This always works. // This shows me what file is being processed, the current time, // the time it was last updated, and the difference between the two. // If $x is less than or equal to 86400, the test passes and processing continues. // But even when the values all align and are good, it fails. if (($cur_time - $updated_time) <= 86400) { // 24 hours // This doesn't work, and the rest of the processing never happens, so the test must have failed. But why?
Everything looks correct. It's a stupidly simple if statement. What could possibly be wrong with it?
I paired it down to the bare essentials and preloaded a couple variables for test purposes:
$showcode = "TEST"; $cur_time = time (); $updated_time = ($cur_time - 50000); // Make like the test should pass. $x = ($cur_time - $updated_time); // DO the math, mostly for short print statement. print "$showcode, $cur_time, $updated_time, $x\n"; // Everything's preloaded and correct. if ($cur_time - $updated_time <= 86400) //which it is ... print "Yes! $showcode, $x\n";?>
When I run this, it works. What could possibly be wrong with the same decision statements in the first sample? The second sample is just a single print statement, not a block enclosed by braces, but so what? I should get the print statement that comes right after the "if" statement is the computed value of ($cur_time - $updated_time) is less than 86400, and as the foreach loop goes around, the first print statement shows me that there are indeed some files in the directory that meet this criterion. What's going on here? This is keep-it-simple-stupid simple. |