Code check

From: Date: Mon, 29 May 2006 21:42:24 +0000
Subject: Code check
Groups: php.general 
Request: Send a blank email to php-general+get-237042@lists.php.net to get a copy of this message
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

« previous php.general (#237042) next »