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
https://forums.phpfreaks.com/topic/72846-solved-class-error/
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
https://forums.phpfreaks.com/topic/72846-solved-class-error/#findComment-367354
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
https://forums.phpfreaks.com/topic/72846-solved-class-error/#findComment-367378
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.