Reputation: 93
i have a array like
$a = array("A", "B", "C");
i have stored the values in database using multiple select.
saved values are "B", "C"
in 2 different rows
I need to show the selected value "b"
and "D"
value in to the same multiple select box.
here the tough concept is i need to display the value of select option from the array as follows
foreach($dbRows as $dbRow) {
// here if i display the selected values using if condition the value are selected by the array values repeats like
a - no selected
b - selected
c - no selected
again loops repeats like
a - no selected
b - no selected
c - selected
}
}
how to display the values in a without repeat?
Upvotes: 0
Views: 602
Reputation: 7065
You can loop the select box array and check if it's value is in DB array using in_array()
$a = array("A", "B", "C");
foreach($a as $v)
{
$selected = in_array($v, $db_array) ? 'selected' : '';
}
Upvotes: 1