Re: selected problem

From: Date: Fri, 26 Apr 2002 14:37:24 +0000
Subject: Re: selected problem
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-18831@lists.php.net to get a copy of this message
on 4/26/02 4:39 AM, its me at fotna@egypt.net appended the following bits to my mbox: > in it i have a form field like this: > <select name="location"> > <OPTION selected value="">Choose City</OPTION> <OPTION > value=10-Ramadan>10-Ramadan</OPTION> <OPTION > value="15 May">15 May</OPTION> <OPTION > value=6-October>6-October</OPTION> <OPTION > value="Abou Redes">Abou Redes</OPTION> <OPTION > and i got from my database: > $location="Alexandria" > so i wanted to appear selected,how can i do this?? Easy solution: Get rid of the word "selected" in the first option. The browser will default to the first anyway. After the <select> tag, echo: <?php echo '<option value="' , $location , '">' , $location , '</option>'; ?> That will list the selected item as the first item in the list. Hard solution: Go thorough the list and put: <?php if ($location == 'Alexandria") { echo ' selected'; } ?> In each of your option tags. (ouch). Less hard solution: Put all of the options into an array and then create the list by looping through the array, each time checking the value to see if it is the selected one using the code above. HTH. Sincerely, Paul Burney <http://paulburney.com/> <?php while ($self != "asleep") { $sheep_count++; } ?>

« previous php.db (#18831) next »