Bir Multiselect kutusunda Seçilen Değerler gösteriliyor

1 Cevap

I have made a single page for adding as well as editing data. In the page i have a multiselect box. I want to know how can i display the selected values in case of editing? My code is :

$categories=$objdb->select("vtiger_cf_601", false, "*", false, false);

$discountstudentInfo = $objdb->select('paytbl_discounts_students', false, "*", "WHERE fk_paytbl_discounts_discountid = '".$_GET['discountid']."' ", false);

<select id="cmbCategory[]" name="cmbCategory[]" class="combo" multiple="multiple">
                            <option value="" selected="selected" >Select</option>
                                        <?php
                                        foreach($categories as $category)
                                        {
                                            foreach($discountstudentInfo as $discountstudentinfo)
                                            {
                                                if($discountstudentinfo[fk_paytbl_discounts_discountid]==$category[cf_601id])
                                                {
                                                    $class="selected=selected";
                                                }
                                                else
                                                {
                                                    $class="";
                                                }
                                        echo '<option value="'.$category[cf_601id].'" "'.$class.'">'.$category[cf_601].'</option>';
                                            }                                           
                                        }       
                                        ?>
                            </select>

Selamlar,

Pankaj

1 Cevap

Sadece değişkenin değerine seçeneğinin değerini karşılaştırmak. Eğer maç, çıkış Seçilen özellik.

<option value="val1" <?php if($value == 'val1') echo selected="selected"; ?> />
<option value="val2" <?php if($value == 'val2') echo selected="selected"; ?> />