Form to edit mysql records. how to do select field
Moderator: General Moderators
Re: Form to edit mysql records. how to do select field
Yeah, that semicolon after ['state'] shouldn't be there
Re: Form to edit mysql records. how to do select field
thank you that works.. now can you please show me how to set the value as like CA and the option show California.. CA is what goes into the DB so i want them to see the full name in the options.. can you show me the example of that array
Re: Form to edit mysql records. how to do select field
You'll need to change your array around a little.
And then your foreach will become
Code: Select all
$states = array(
'CA' => 'California',
'NY' => 'New York',
'VT' => 'Vermont',
);Code: Select all
<?php foreach ($states as $abbr => $state): ?>
<option value="<?= $abbr; ?>" <?= ($abbr == $user['state']) ? 'selected="selected"' : ''; ?>>
<?= $state; ?>
</option>
<?php endforeach; ?>Re: Form to edit mysql records. how to do select field
thank you that works..
one more thing.. when they're done editing their page i have another page that displays their state from the db . it shows just the abbr because thats whats stored in the database. can you show me how to do the same thing and show the full state name .
thanks so much
one more thing.. when they're done editing their page i have another page that displays their state from the db . it shows just the abbr because thats whats stored in the database. can you show me how to do the same thing and show the full state name .
thanks so much
Re: Form to edit mysql records. how to do select field
Use the same states array. Assuming your user's values are stored in $user,
Code: Select all
echo $states[$user['state']];Re: Form to edit mysql records. how to do select field
thank you so much you saved me a lot of time and headache!!!!