开发者

Showing Selected Values on a Multiselect box

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="";
          开发者_如何学Go                                      }
                                        echo '<option value="'.$category[cf_601id].'" "'.$class.'">'.$category[cf_601].'</option>';
                                            }                                           
                                        }       
                                        ?>
                            </select>

Regards,

Pankaj


Just compare the value of the option to the value of the variable. If it matches, output the selected attribute.

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜