Solution 1 :

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' : '';

Problem :

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?


Comment posted by Maximilian Fixl

Please update your question by changing the tags. Missing javascript in your code.

Comment posted by nice_dev

Basic check with

Comment posted by Aravindan

Not up to results. Expecting little more but, its useful.

Comment posted by Samir

Thanks Aravindan. We at SO are here to fix the problem, and not to code completely for you. This is how you learn.

Comment posted by Aravindan

What i expect is a clue to work for that that is it.