I have a little problem with a selectbox that have to have some marked options from a URL parameter.
I have an URL that can look like this
index.php?page=edit&lid=4&recs=1,4,7&hl=Test&lhash=7c2cd87dad07ac99a00e92041a5d6a38
Where I want to use 1,4,7 from the recs parameter to mark the mailgroups with ID 1, 4 and 7 in my selectbox like
<select name="groups" multiple="multiple">
<option value="1" selected="selected">Group 1</option>
<option value="2">Group 2</option>
<option value="3">Group 3</option>
<option value="4" selected="selected">Group 4</option>
<option value="5">Group 5</option>
<option value="6">Group 6</option>
<option value="7" selected="selected">Group 7</option>
<option value="8">Group 8</option>
</select>
I tried to use this to make a variable with the selected=”selected” value
$recis = explode(",", $_GET["recs"]);
foreach($recis as $rec) {
if($row["mailgroup_id"] == $rec) {
$sel = 'selected="selected"';
} else {
$sel = '';
}
}
And then
<option value="'. $row["mailgroup_id"] .'" '. $sel .'>'. $row["mailgroup_name"] .' - '. $row["country"] .'</option>
But that doesn’t seem to work as all groups become marked
why don’t you try loop on mailgroup_id record set
Option Code