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' : '';
}
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' : '';
}
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?
Please update your question by changing the tags. Missing javascript in your code.
Basic check with
Not up to results. Expecting little more but, its useful.
Thanks Aravindan. We at SO are here to fix the problem, and not to code completely for you. This is how you learn.
What i expect is a clue to work for that that is it.