Page 2 of 2

Re: Form to edit mysql records. how to do select field

Posted: Fri Aug 29, 2014 2:01 pm
by Celauran
Yeah, that semicolon after ['state'] shouldn't be there

Re: Form to edit mysql records. how to do select field

Posted: Fri Aug 29, 2014 2:05 pm
by donny
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

Posted: Fri Aug 29, 2014 2:09 pm
by Celauran
You'll need to change your array around a little.

Code: Select all

$states = array(
	'CA' => 'California',
	'NY' => 'New York',
	'VT' => 'Vermont',
);
And then your foreach will become

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

Posted: Fri Aug 29, 2014 2:15 pm
by donny
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

Re: Form to edit mysql records. how to do select field

Posted: Fri Aug 29, 2014 2:17 pm
by Celauran
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

Posted: Fri Aug 29, 2014 2:22 pm
by donny
thank you so much you saved me a lot of time and headache!!!!