Re: New way to make select boxes auto select
| From: | Richard Lynch | Date: | Fri, 26 Jul 2002 17:18:48 +0000 |
| Subject: | Re: New way to make select boxes auto select | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-109821@lists.php.net to get a copy of this message | ||
>You may already be doing it like this, but I think I found a new way to
>make select boxes auto-select (what data they put in) a lot easier. All you
>have to do is put a variable in each select tag that is equal to the value
>of the select option i.e.: <option value=teacher $teacher> -- then all you
>have to do is base the variable on that <select name=interest> $$interest =
>"selected"; quick and easy with out having to loop through an if elseif
>statement. Let me know if you like that method or have any objections.
Since I'm always looping through choices in my database, and not hard-coded
values, it's really no trouble to do:
while ($id = ...){
$selected = $id == $previously_selected_id ? 'SELECTED' : '';
echo "<OPTION VALUE=$id $selected>...</OPTION>\n";
}
If I *really* want hard-coded options, I'll just put them in an array and do
the above.
--
Like Music? http://l-i-e.com/artists.htm
I'm looking for a PRO QUALITY two-input sound card supported by Linux (any
major distro). Need to record live events (mixed already) to stereo
CD-quality. Soundcard Recommendations?
Software to handle the recording? Don't need fancy mixer stuff. Zero (0)
post-production time. Just raw PCM/WAV/AIFF 16+ bit, 44.1KHz, Stereo
audio-to-disk.