how to show selected multiple options of drop down in php


Journey With Me

I have to store the Multiple values from drop down list into db

I want retrieve the those value and display into the drop down list

Solution

first u get that value explode those value into one variable

$p_language_code=explode(‘,’,$p_mother_tongue_code);

use in-array function function in to check ,whether the value selected or not

<?php if(in_array($row[‘id’],$p_language_code)){echo “selected=selected”;}else{echo “”;}?>>

COMPLETE SOURCE

<select class="inputtext" style="width:190px;" name="pro_mother_tongue[]" size="1" id="pro_mother_tongue" multiple="multiple" >
              <option value="">--Select Mother Tongue--</option>
            <?php  
            //split the language list
            $p_language_code=explode(',',$p_mother_tongue_code);
            $mother_toue=mysql_query("SELECT * FROM mother_tongue")or die(mysql_error());
                while($row=mysql_fetch_array($mother_toue)){
            ?>
                    <option value="<?php  echo $row['id'];?>" <?php if(in_array($row['id'],$p_language_code)){echo "selected=selected";}else{echo "";}?>><?php  echo $row['language'];?></option>                
            <?php 
            }?>
            </select>

View original post

Advertisements