Jump to content

[SOLVED] can you see any difference?


corillo181

Recommended Posts

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>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.