Re: <OPTION

From: Date: Thu, 26 Oct 2006 01:57:35 +0000
Subject: Re: <OPTION
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-243637@lists.php.net to get a copy of this message
On Wed, 2006-10-25 at 17:35 -0700, Paul Novitski wrote: > 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; > } Ewww, I'll take Stut's style anyday. Heredoc has its uses, but I wouldn't consider your above usage one of them :/ Now to add my own flavour... <?php for( $day = 1; $day <= 31; $day++ ) { $selected = $selected_day_of_month == $day ? ' selected="selected"' : ''; echo '<option value="'.$day.'"'.$selected.'>' .$day .'</option>'; } ?> Cheers, Rob. -- .------------------------------------------------------------. | InterJinn Application Framework - http://www.interjinn.com | :------------------------------------------------------------: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `------------------------------------------------------------'

« previous php.general (#243637) next »