Jump to content

[SOLVED] class error


corillo181

Recommended Posts

can anyone see where is this error coming from?

 

Parse error: syntax error, unexpected T_VARIABLE, expecting T_FUNCTION in C:\wamp\www\untitled.php on line 29

<?php
class calendar{
var $year;
var $month;    
var $endDay;

function calendar($y,$m){
	$this->year = $y;
	$this->month = $m;
	$this->startDate=mktime(12,0,0,$this->month,1,$this->year);
	$this->andDay = date('t',$this->startDate);
	$this->allTime = getdate($this->startDate);

}

function displayCells(){
	for($count=0;$count < (6*7);$count++){				
			if(($count%7)==0){
				if($this->allTime['mon'] != $this->month){
					break;
				} else {
				echo '<tr></tr>';
			}
	}
}

}

$cal = new calendar(2007,10);
echo '<table border="2"><tr>';
$cal->displayCells();
echo '</tr></table>';
?>

Link to comment
Share on other sites

You never closed the brackets to your class.

 

<?php

class calendar{
    var $year;
    var $month;
    var $endDay;
    
    function calendar($y,$m)
    {
        $this->year = $y;
        $this->month = $m;
        $this->startDate=mktime(12,0,0,$this->month,1,$this->year);
        $this->andDay = date('t',$this->startDate);
        $this->allTime = getdate($this->startDate);
        
    }
    
    function displayCells()
    {
        for ($count=0; $count < (6*7); $count++) {
            if (($count%7)==0) {
                if ($this->allTime['mon'] != $this->month) {
                    break;
                } else {
                    echo '<tr></tr>';
                }
            }
        }     
    }
}
    
    $cal = new calendar(2007,10);
    echo '<table border="2"><tr>';
    $cal->displayCells();
    echo '</tr></table>';
    
?>

Link to comment
Share on other sites

additional question.  i added some more to the class and it works nicely

but how would i find which is the first day of the month..like a Saturday or Tuesday.

<?php
class calendar{
var $year;
var $month;    
var $endDay;

function calendar($y,$m){
	$this->year = $y;
	$this->month = $m;
	$this->startDate=mktime(12,0,0,$this->month,1,$this->year);
	$this->andDay = date('t',$this->startDate);
	$this->allTime = getdate($this->startDate);

}

function displayCells(){

$days = array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
//takes each day of the array and makes it in to the head days

foreach($days as $day){
echo"<td align=\"center\">$day</td>";

}

	for($count=0;$count < (6*7);$count++){	
		$dayArray=getdate($start);		
			if(($count%7)==0){
				if($this->allTime['mon'] != $this->month){
					break;
				} else {
				echo '<tr></tr>';
					}
			}
	if($count < $this->andDay){
				      echo "\t<td>$count</td>\n";
	} else {
echo '<td>blank</td>';
$start +=(60*60*24);
	}
}

}
}

$cal = new calendar(2007,10);
echo '<table border="2"><tr>';
$cal->displayCells();
echo '</tr></table>';
?>

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.