I have a user account form, which form has drop down lists.
When the user returns to their account page I want to auto select the drop down list items that they have previously selected and were thus saved in their records. However when the page is generated by Php somehow ONLY the 1st previously selected item is selected and not the rest. Can someone tell me what the HEK is going on and what is the solution?
FYI, here is a sample of the related page:
and here is the sample Php code for it:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> Testing In Array</TITLE>
<META NAME="Description" CONTENT="">
</HEAD>
<BODY>
<?php
$country = 'United States, Australia, United Kingdom';
$country_array = explode(',', $country);
?>
<form>
<select name="country[]" size="6" multiple>
<option value="-1" <?php if (isset($country_array) AND (count($country_array) > 0)) {echo ''; } else {echo 'selected';} ?>>Not Selected</option>
<option value="United States" <?php if (isset($country_array) AND (in_array('United States', $country_array))) {echo 'selected'; } ?>> United States </option>
<option value="United Kingdom" <?php if (isset($country_array) AND (in_array('United Kingdom', $country_array))) {echo 'selected'; } ?>>United Kingdom</option>
<option value="Australia" <?php if (isset($country_array) AND (in_array('Australia', $country_array))) {echo 'selected'; } ?>>Australia</option>
<option value=Canada <?php if (isset($country_array) AND (in_array('Canada', $country_array))) {echo 'selected'; } ?>>Canada</option>
<option value=Algeria>Algeria</option>
<option value="American Samoa">American Samoa</option>
</select>
</form>
</BODY>
</HTML>
Well this array I am showing here is just a sample.
The actual array is a field in a MySQL Table.
So when the field from MySQL is selected, then the result is something like this:
$country = ‘United States, Australia, United Kingdom’;
which then I am converting into an array with:
$country_array = explode(‘,’, $country);
so since explode does not produce this which you have suggested:
array(‘United States’,’ Australia’,’ United Kingdom’);
How am I supposed to go from:
$country = ‘United States, Australia, United Kingdom’;
to that array which you have suggested that explode()
does not produce?