----- Original Message ----- From: "David Chamberlin" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Friday, January 03, 2003 1:27 PM Subject: [PHP] One more form question
> OK, last one was answered quickly and successfully (thank you!), so > here's another one. > > Is there an easy way to set something in a select list to be selected? > Right now I'm doing a real brute-force method. e.g., > > echo "<td><select name=\"disp_address\">"; > $choices = array( 'pub' => 'On Public Page', > 'members' => 'Only on Members Page', > 'nodisp' => 'Do not Display' ); > foreach ( $choices as $key => $choice ) { > $selected = ''; > if ( strcmp( $key, $member_info->display_address ) == 0 ) { > $selected = 'selected'; > } > echo "<option value=\"$key\" $selected>$choice"; > } > echo '</select></td>'; > > I've got to imagine there's a better way .... > > Thanks, > Dave Okay let me take another hack at one of your questions and maybe I won't screw up this time. ;-) PHP has no functional control over the HTML content. You could make it easier on yourself by writing a function that outputs 'selected' or null instead of coding a separate conditional for each form element, but other than that this is the only way to do it. -Kevin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php