Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Dear all I would appreciate it greatly if anyone could help with this code. My knowledge does not go beyond a few tutorials. I get this error message:
"Parse error: syntax error, unexpected T_VAR, expecting '{' in c:\program files\apache group\Apache\htdocs\date_pulldown.class.php on line 3"
when I try to run when I run the code below. My basic understanding tells me that when script [1] tries to communicate with script [2] it balks on line 3 - thanks in advance:
[1]Code: Select all
<html>
<head>
<title>Listing 12.4 Using the date_pulldown Class</title>
</head>
<?php
include("date_pulldown.class.php");
$date1 = new date_pulldown("fromdate");
$date2 = new date_pulldown("todate");
$date3 = new date_pulldown("foundingdate");
$date3->setYearStart(1972);
if (empty($foundingdate))
$date3->setDate_array(array('mday'=>26, 'mon'=>4, 'year'=>1984));
?>
<body>
<form>
From:<br>
<?php print $date1->output(); ?><p>
To:<br>
<?php print $date2->output(); ?><p>
Company founded:<br>
<?php print $date3->output(); ?><p>
<input type="submit">
</form>
</body>
</html>[2]
Code: Select all
<?PHP
class date_pulldown
var $name; //offending, line 3, tried switching 'var' to 'private' no fix
var $timestamp = -1;
var $months = array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
var $yearstart = -1;
var $yearend = -1;
function date_pulldown($name) {
$this->name = $name;
}
function setDate_global() {
if (!$this->setDate_array($GLOBALS[$this->name])) {
return $this->setDate_timestamp(time());
}
return true;
}
function setDate_timestamp($time) {
$this->timestamp = $time;
return true;
}
function setDate_array($inputdate) {
if (is_array($inputdate) &&
isset($inputdate['mon']) &&
isset($inputdate['mday']) &&
isset($inputdate['year'])) {
$this->timestamp = mktime(11, 59, 59,
$inputdate['mon'], $inputdate['mday'], $inputdate['year']);
return true;
}
return false;
}
function setYearStart($year) {
$this->yearstart = $year;
}
function setYearEnd($year) {
$this->yearend = $year;
}
function getYearStart() {
if ($this->yearstart < 0) {
$nowarray = getdate(time());
$this->yearstart = $nowarray[year]-5;
}
return $this->yearstart;
}
function getYearEnd() {
if ($this->yearend < 0) {
$nowarray = getdate(time());
$this->yearend = $nowarray[year]+5;
}
return $this->yearend;
}
function output() {
if ($this->timestamp < 0) {
$this->setDate_global();
}
$datearray = getdate($this->timestamp);
$out = $this->day_select($this->name, $datearray);
$out .= $this->month_select($this->name, $datearray);
$out .= $this->year_select($this->name, $datearray);
return $out;
}
function day_select($fieldname, $datearray) {
$out = "<select name=\"$fieldname"."[mday]\">\n";
for ($x=1; $x<=31; $x++) {
$out .= "<option value=\"$x\"".($datearray['mday']==($x)
?" SELECTED":"").">".sprintf("%02d", $x) ."\n";
}
$out .= "</select>\n";
return $out;
}
function month_select($fieldname, $datearray) {
$out = "<select name=\"$fieldname"."[mon]\">\n";
for ($x = 1; $x <= 12; $x++) {
$out .= "<option value=\"".($x)."\"".($datearray['mon']==($x)
?" SELECTED":"")."> ".$this->months[$x-1]."\n";
}
$out .= "</select>\n";
return $out;
}
function year_select($fieldname, $datearray) {
$out = "<select name=\"$fieldname"."[year]\">";
$start = $this->getYearStart();
$end = $this->getYearEnd();
for ($x= $start; $x < $end; $x++) {
$out .= "<option value=\"$x\"".($datearray['year']==($x)
?" SELECTED":"").">$x\n";
}
$out .= "</select>\n";
return $out;
}
}
?>feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]