I am trying to load a mulitple select from the database to edit.
I am storing the original data in an imploded string (ie “4, 6, 8, 9”).
What I want to do is explode that string from the database, then have the values selected when the edit form is loaded. The values are Float, then 1-52.
Here is the code I have so far, but it does not select the values.
$listing->getWeeksAvail() is just a call that returns the WeeksAvail property in this case “4, 6, 8, 9)
<?php
$weeks_available = explode(",", $listing->getWeeksAvail());
if (in_array("Float", $weeks_available)) {
echo " selected='selected'";
}
?>
>Float</option>
<?php
for($float=0; $float<=52; $float++) {
echo "<option value=\"$float\"";
if (($listing instanceof listing) && $float == $listing->getWeeksAvail()) {
echo " selected='selected'";
}
echo ">$float</option>\n";
}
The second part of your code should be like this: