Re: <OPTION

From: Date: Thu, 26 Oct 2006 00:35:43 +0000
Subject: Re: <OPTION
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-243636@lists.php.net to get a copy of this message
At 10/25/2006 04:09 PM, Stut wrote:
Dang that's painful!! Try this... <?php
    foreach (range(1, 31) as $day)
    {
        print '<option value="'.$day.'"';
        if ($selected_day_of_month == $day)
            print ' selected';
        print '>'.$day.'</option>';
    }
?>
Ouch! Gnarly mix of logic and markup. I suggest something more like:
        foreach (range(1, 31) as $day)
        {
                $sSelected = ($selected_day_of_month == $day) ? ' selected="selected"' : '';
                print <<< hdDay
                <option value="$day"$sSelected>$day</option>
hdDay;
        }


« previous php.general (#243636) next »