> Hi there, can anyone tell me how to fix my code so that on the last day of
> the month, my code doesn't repeat the months...

I'm not sure what you mean by this, but I can be a moron on this list
sometimes and the clear answer usually comes to me about 2 seconds after I
hit the send button. Do you mean that you don't want any months in the
SELECT control when it's the last of the month? Or you don't want the
SELECTED attribute in the OPTION tags? As far as I can tell, you're not
repeating any months, but you're only listing them once.

Try this (and IMHO a *slight* *slight* improvement in clarity, but again,
that's my HO):

<select name="month">
<?
    for ($counter=1; $counter<=12; $counter++) {
        print "<option value=\"". $counter . "\"";
        if (($counter == date("m")) || (date("d") < date("t"))) {
            print " selected";
        }
        print ">" . date("F",mktime(0,0,0,$counter,date("d"),date("Y"))) .
"</option>";
    }
}
</select>

I adjusted it so that you only print out the SELECTED attribute if it's the
current month, and I called $i as $counter, because, to me anyway, it makes
it clearer what is the $counter. If $i works for you, though, there's
nothing wrong with that, and it's not that it's unclear anyway, what with it
in the FOR loop only a few lines earlier. (I'll shut up now about $counter.)

Anyway, I added a comparison above that said if the current date is less
than the last day of the month, then print SELECTED. That's assuming I have
your question right in that you don't want to select the current month if
it's the last day of that month. Otherwise, if I'm wrong, you can take that
comparison and put it just about anywhere.

Help? Doesn't? Am I a complete goof?


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

Reply via email to