RE: [PHP] dynamic form help
| From: | Cristian Donoso | Date: | Wed, 22 Nov 2000 08:27:33 +0000 |
| Subject: | RE: [PHP] dynamic form help | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-26582@lists.php.net to get a copy of this message | ||
> What would be the best way to do the following? I have a mysql db record,
I
> have it so people can login against the db and now I want to allow them to
> edit the information about them in the db. The form they create their
entry
> with is a combination of text boxes and drop-down selection menus. When
> they log in I want the form that comes up to have the values in it that
they
> originally signed up with. I know how to populate the text box fields
> dynamicly with value=$var_name , but how can I make it so that the
selection
> drop-down menus have what they selected? I essentially need to be able to
> write those parts of the form like this:
>
> drop-down:
>
> You have 3 choices, your current selection is...you can change it if you'd
> like and save it to the db:
> <SELECT>
> <OPTION>1</OPTION>
> <OPTION selected>2</OPTION>
> <OPTION>3</OPTION>
> </SELECT>
>
> how can I make it so that the 'selected' appears in the right place? and
> yet still include all the other options so they can change it if they want
> to?
If you have stored in your DB the option, you can do something like this:
print "<SELECT>";
for ($i=1 ; $i<=3; $i++) {
($i == $value_from_database) ? $sel = "selected" : $sel = "";
print "<OPTION $sel>$i</OPTION>";
}
print "</SELECT>";
this only works if the $value_from_database is an INTEGER but that's the
idea.
______________________________
Cristian Donoso Monteiro
Temuco - Chile