Code check

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi all,

I wrote a php script that creates options for select boxes. What this
script does is selects tomorrows date.  However I have tested the code
when the day is the last day of the month and the script blows up.
Instead of displaying June it displays January and repeats the months
12 times I think.  I didn't count I just noiced thart that the months
of the year were repeated multiple times.

I think my problem is with the mktime function.  I don't think it
likes $i+1 too well.  I also want to be sure that this code takes care
of all date contitions like leap year, end of the year and any other
condition that would give a wrong date.

So here is my code:

<select name="month">
<?php
foreach(range(1,12) as $i)
{
	if (date('t') == date('j'))
	{
		echo "<option value=$i+1 selected=\"true\">" . date('F',
mktime(12,0,0,$i+1,1)) . "</option>\n";
	}
	if (date('n') == $i)
	{
		echo "<option value=$i selected=\"true\">" . date('F',
mktime(12,0,0,$i,1)) . "</option>\n";
	}
	else
	{
		echo "<option value=$i>" . date('F', mktime(12,0,0,$i,1)) . " </option>\n";
	}
}

?>
</select>
<br />
<br />
<select name="day">
<?php
foreach (range (1,31) as $i)
{
	if (date('j')+1 == $i)
	{
		echo "<option value=$i selected=\"true\">" . date('j',
mktime(12,0,0,0,$i,date('Y'))) . "</option>\n";
	}
	else
	{
		echo "<option value=$i>" . date('j', mktime(12,0,0,0,$i,date('Y')))
. "</option>\n";
	}
}

?>
</select>
<br />
<br />
<select name="year">
<?php
if (date('n') == 12 && date('j') == 31 )
{
	echo "<option value=" . date('Y')+1 . " selected=\"true\">" .
date('Y')+1 . "</option>\n";
}
else
{
	echo "<option value=" . date('Y') . " selected=\"true\">" . date('Y')
. "</option>\n";
}
?>
</select>

Any help will be appreciated

Paul

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux