Forum Moderators: coopster

Message Too Old, No Replies

comparison operator problem

         

firemaster

8:23 am on Feb 2, 2007 (gmt 0)

10+ Year Member



I am trying to use a simple greater then comparison but am having a problem. I have tried multiple ways and can't figure out why it doesn't work.

if(07 >= $week1 && $week1 > 00)
{
$week2 = 1;
}

if(07 >= $week1 && $week1 > 00) $week2 .= 1;

I have tried using quotes on all the numbers, setting the numbers as $vars before setting them in the IF statement. I just don't know why it doesn't work. If I were to do (07 >= $week1 > 00) I would get a parse error on the '>' but I don't think that would return the same result anyway.

The problem is that $week2 comes out empty.

please help me figure this out.
thanks a lot,
Mike

eelixduppy

12:01 pm on Feb 2, 2007 (gmt 0)



The syntax looks fine. The only problem that it could be is that
$week1
does not fall within that range of numbers, or it is not in a number format like that, but something entirely different. Before you try the comparison, echo out the value of
$week1
to see if it is exactly what you want it to be. Then from there you can adjust other code accordingly.

mcibor

3:28 pm on Feb 2, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I tested your code on the following page:

test.php?week=08

<?php
$week1 = "null";
$week2 = "null";
if(isset($_GET['week']))
{
$week1 = $_GET['week'];
if(07 >= $week1 && $week1 > 00) $week2 = 1;
else $week2 = 0;
}
echo "Week1: $week1<br />Week2: $week2";
?>

and it works as expected.

Therefore there must be some other problem
Try echoing the $week1, as eelix suggested. And also turn error_reporting(E_ALL);

Regards
Michal

firemaster

4:47 pm on Feb 2, 2007 (gmt 0)

10+ Year Member



I have already tried echoing it, $week1 seems fine. it's actually

$week1 = date('d');

which prints out as '02' right now. How would I go about turning the error_reporting on? I'm just trying to set a value to 1-4 depending on what day it is 01-07, 07-14, etc. I dont' know if there is another way to do this because I didn't think there was too much wrong with my code. Unless it is the date function doing something?
thanks,
Mike

firemaster

10:25 pm on Feb 2, 2007 (gmt 0)

10+ Year Member



Fixed, found out the error was in a '

mcibor

2:35 pm on Feb 5, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi Mike

just that you know:

<?php
error_reporting [php.net](E_ALL);
?>

this is how you turn all errors to show up.
Glad you found the mistake!
Michal