Re: Session variables

From: Date: Mon, 08 Jul 2002 12:40:50 +0000
Subject: Re: Session variables
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-106073@lists.php.net to get a copy of this message
Thanks Justin, your solution is spot-on! Regards Steve Justin French wrote: > <SELECT name="day"> > <OPTION value="please select" <? if(empty($day)) { echo > "selected"; } > ?>> > <OPTION value="monday" <? if($day == "monday") { echo > "selected"; } ?>> > <OPTION value="tuesday" <? if($day == "tuesday") { echo > "selected"; } > ?>> > <OPTION value="wednesday" <? if($day == "wednesday") { echo > "selected"; > } ?>> > <OPTION value="thursday" <? if($day == "thursday") { echo > "selected"; } > ?>> > <OPTION value="friday" <? if($day == "friday") { echo > "selected"; } ?>> > </SELECT> > > Obviously this is labourios to code... you can do this a lot smarter/quicker > with an array for the entire select box... have an array of days, and do a > foreach loop which writes the all the options for you, with the if > statements, etc etc. > > By the way, this has nothing to do with sessions :) > > It's purely about how to populate drop-down menus from an array, and how to > have the correct value selected if it exists, else showing a default > selection. > > Cheers, > > Justin French > > on 08/07/02 9:36 PM, Steve Fitzgerald (oneeightone@netscape.net) wrote: > > > I am designing a form using sessions in which the user inputs their > > details on page 1 and after submitting they are directed to page 2 for > > confirmation. They then have the option of editing their input (ie they > > are returned to page 1) where their previous input is reflected in the > > form fields by > > value ='<?php echo $var ?>' > > This works fine except if the input type is a drop down box, in which > > case the default <option> is shown. Is there any way around this? How > > can I show the user their previous choice in these boxes? > > Any insights would be appreciated. > > Steve > >

« previous php.general (#106073) next »