PDA

View Full Version : displaying dates


sarah
06-16-2003, 04:49 PM
Hi,

At the moment I use the code below to display the months that users can select:

<select size="1" name="D1">
<?php
writeSingleOption("JAN", "1", $stmonth);
writeSingleOption("FEB", "2", $stmonth);
writeSingleOption("MAR", "3", $stmonth);
writeSingleOption("APR", "4", $stmonth);
writeSingleOption("MAY", "5", $stmonth);
writeSingleOption("JUN", "6", $stmonth);
writeSingleOption("JUL", "7", $stmonth);
writeSingleOption("AUG", "8", $stmonth);
writeSingleOption("SEP", "9", $stmonth);
writeSingleOption("OCT", "10", $stmonth);
writeSingleOption("NOV", "11", $stmonth);
writeSingleOption("DEC", "12", $stmonth);
?>
</select>

I have added the following if statement around the <select>

<?php
if($method=="DD") {
?>

and </select>

<?php
}
?>

If the method is "DD" then the user can only select the current month and next month. I already have done this with the year using the following:

writeSingleOption(date("Y",time()), "", $styear);
writeSingleOption(date("Y",time())+1, "", $styear);

but when itried the following code:

writeSingleOption(date("M",time()), "", $stmonth);
writeSingleOption(date("M",time())+1, "", $stmonth);

this didn't work.

Any ideas how I can achieve this?

Thanks in advance

Sarah

mordred
06-17-2003, 01:36 AM
It would surely help to see the function writeSingleOption() to verify my answer, but anyway, here it goes:

I think you use the wrong modifier in the date() call for the month. 'M' gives you back the first three letters of a month's name, so adding 1 to that doesn't make much sense. I think you rather need date('n') instead which gives you back the month integer.

sarah
06-17-2003, 10:15 AM
Hi Modred,

here is the code for the function:

function writeSingleOption($strText, $strValue, $strSelected) {
echo "<option";
if (strlen($strValue)>0) {
echo " value=\"".htmlspecialchars($strValue)."\"";
$text=$strValue;
}
else {
$text=$strText;
}
if ($text==$strSelected) {
echo " selected";
}
echo ">".htmlspecialchars($strText)."</option>\n";
return TRUE;
}

But I got it to work, I put an if statement around each month and this seems to work at the moment. Its only a temp fix until I can code summat more cleverer.

Thanks for your help

Sarah

duniyadnd
06-17-2003, 12:55 PM
Just FYI, you don't need to return true at the end, cause you're not returning to any variable later on, unless you are going to use objects which I don't see in your code yet.. :confused: