corillo181 Posted July 3, 2007 Share Posted July 3, 2007 i got this calendar to tell me the current month.. the problem is i use it in one page and it works fine and then i try using it in another page and it does not work both pages are empty this all there is in both the pages.. the problem in the second page the week starts one day earlier.. so if the first day was on Monday it would say Sunday is the first day. page1 works <? $month=date("m"); $year=date("Y"); $start=mktime(12,0,0,$month,1,$year); $firstDayArray = getdate($start); $days= array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"); ?> <table border="1" cellpadding="5"> <? foreach($days as $day){ echo "<td><b>$day</b></td>"; ?> <? } for($count=0;$count < (6*7);$count++){ $dayArray=getdate($start); if (($count % 7)==0){ if($dayArray['mon'] != $month){ break; } else { echo "</tr><tr>\n"; } } if($count < $firstDayArray['wday'] || $dayArray['mon'] !=$month){ echo "\t<td><br></td>\n"; } else { echo "\t<td>".$dayArray['mday']." </td>\n"; $start +=(60*60*24);; } } ?> </tr></table> page2 does not work <table border="1" cellpadding="5"> <? $month=date("m"); $$year=date("Y"); $start=mktime(12,0,0,$month,1,$year); $firstDayArray = getdate($start); $days= array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"); foreach($days as $day){ echo"<td><b>$day</b></td>"; } for($count=0;$count < (6*7);$count++){ $dayArray=getdate($start); if (($count % 7)==0){ if($dayArray['mon'] != $month){ break; } else { echo "</tr><tr>\n"; } } if($count < $firstDayArray['wday'] || $dayArray['mon'] !=$month){ echo "\t<td><br></td>\n"; } else { echo "\t<td>".$dayArray['mday']." </td>\n"; $start +=(60*60*24); } } ?> </tr> </table> Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted July 3, 2007 Share Posted July 3, 2007 Line 5 or 6 in secound page: $$year=date("Y"); Notice the $$year. There is your problem. remove the extra $ There you are setting up a variable variable. A variable variable where you can set a variable name as the value of another variable, eg: $foo = 'bar'; $bar = 'hello world'; echo $$foo; Now as the year variable in your code does not exist yet PHP cannot create a variable variable and thus it is probably causing the problem you are having Quote Link to comment Share on other sites More sharing options...
corillo181 Posted July 3, 2007 Author Share Posted July 3, 2007 wow man i can't believe this.. i did not notice this for the last hour trying to find out what was the problem man.. like they say 4 eyes are better then 2. thanx man. Quote Link to comment Share on other sites More sharing options...
Barand Posted July 3, 2007 Share Posted July 3, 2007 Use code tags, please. your code here 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.