Page 1 of 1

Trouble using getdate() stuff in if statement

Posted: Fri Jan 17, 2003 11:43 pm
by SephFFG
The following code does not work for some reason. Could someone please help me.

Code: Select all

$memberrow = mysql_fetch_row(mysql_query("SELECT * FROM main_topsites where id=$id"));
	$dateInfo = getdate();
 	$yearday=$dateInfoї"yday"];
 	$year=$dateInfoї"year"];
 	$memberday="$memberrowї12]";
 	$memberyear="$memberrowї13]";
 if ($yearday>$memberday || $year>$memberyear)
   {
      $memberrowї10]++;
      mysql_query("UPDATE main_topsites set hitsin='1',hitsout='0',totalin='$memberrowї10]',day='$dateInfoїyday]',year='$dateInfoїyear]' where id=$id");
   }
  else
   {
     $memberrowї8]++;
     $memberrowї10]++;
     mysql_query("UPDATE main_topsites set hitsin='$memberrowї8]',totalin='$memberrowї10]' where id=$id");
   }
No matter what the if statement, even if it is "$yearday==0" the script always does the if, not the else portion. If you would like to see the problem in action, go to http://www.ffgurus.net/topsites/index.p ... hitin&id=2 When you refresh, both of the hits in categories should increase, only the total does.

Posted: Sat Jan 18, 2003 12:21 am
by volka
if you put

Code: Select all

echo "<!--  if ($yearday>$memberday || $year>$memberyear) -->"
right before the actual if-statement what does it show in the "source view" of your browser?

Posted: Sat Jan 18, 2003 9:58 am
by SephFFG
It prints:

Code: Select all

<!--  if (17>17 || 2003>2003) -->

Posted: Sat Jan 18, 2003 10:05 am
by volka
then it enters the else-block. Neither is 17 greater than 17 nor 2003 greater than 2003 ;)

Posted: Sat Jan 18, 2003 10:18 am
by SephFFG
But it doesn't. It still enters the if block and not the else.

Posted: Sun Jan 19, 2003 1:09 am
by gyardleydn
This probably is not it, but does volka's echo statement, or the branch taken change if you alter

Code: Select all

$memberday="$memberrow&#1111;12]"; 
   $memberyear="$memberrow&#1111;13]";
to

Code: Select all

$memberday= (integer) $memberrow&#1111;12]; 
   $memberyear= (integer) $memberrow&#1111;13];
:?:

Posted: Sun Jan 19, 2003 1:28 pm
by SephFFG
Thanks a bunch. Defining them as integers fixed the problem. Thanks again.

Posted: Sun Jan 19, 2003 6:10 pm
by volka
damned auto-cast :D