Why Isn't This Php Code Working?

I'm trying to make this calendar for my web-page ( http://andrewtarium.openzero.com ), but I cannot get this script to work

          for($i = 0; $i < 6; $i++)
         {
         echo "<tr> \n <td align=\"center\"> \n <table cellpadding=\"0\" cellspacing=\"0\" border=\"0\">";
         echo "<tr> \n <td width=\"6\"><img src=\"images/calend.gif\"></td>";
           for($x = 0; $x < 8; $x++)
           {
             if($print == 0)
             {
               if($first == $x)
               {
                 $print == 1;
               }
               else
               {
                 echo "<td width=\"18\" class=\"daten\"> </td>";
               }
             }
             if($print == 1)
             {                
               echo "<td width=\"18\" ";
               if ($dayon == $today)
               {
                 echo "class=\"datet\"> </td>";
               }
               else
               {
                 echo "class=\"date\"> </td>";
               }
               $dayon++;
             }
           }
           echo "<td width=\"6\"><img src=\"images/calend1.gif\"></td> \n </tr> \n </table> \n </td> \n </tr>";
         }

Yes, I did declaire the variables. It seems that print never gets changed. Print finds out whether the first day (sun, mon) has arrived so I can start to fill in the rest of the month. $i controls the week and $x controls the day (sun, mon...). $first is the numerical day (0 = sun...). Evidently, this line "if($first == $x)" is always false. I cannot figure out why.

#73369

More info on what's going on.

I printed out the $first and $x for every day and it skips the day that it is actually on. Therefore the loop goes 0, 1, 2, 3, 4, 5, 7, no 6.

#73370

Well, first of all, there are only 7 days in a week, and your loop makes $x pass through 8 numbers (0,1,2,3,4,5,6,7 <-- count'em, there're 8)....

::edit::

Also:

if($first == $x)
              {
                $print == 1;
              }

should be

if($first == $x)
              {
                $print = 1;
              }

... it probably skipped the day it's on because you put the print statements in a strange place.

#73376

Well, that is the problem, when I put seven, it only goes through the loop 6 times.

#73377

read edited post.

loop does go through seven times when you put seven. your print== screwed stuff up

#73378

Thanks, I always make that mistake in C++. :nuts:

Works fine now. Thanks a lot Cerebral.

#73379

Glad to help. ;) Common mistake, don't beat yourself up over it. :P

#73383