Sumit Nair
Sumit Nair

Reputation: 337

How to update select2 drop down in codeigniter

Hi i am using select2 jquery plugin to insert multiple values to a drop down but when i am trying to update i am facing problem can anyone help me out in showing the right way of doing this

<?php 
    $cats = explode(',',$r['keyword_whomtoteach']);
    foreach($cats as  $vald) {
        foreach($keyword as $key=>$keywords) { 
            if ($vald == $keywords->keyword_id) { ?>                         
                <option value="<?php echo $keywords->keyword_id; ?>" <?php { echo "selected"; }  ?>><?php echo $keywords->keyword_name; ?></option> <?php } else { ?>
                <option value="<?php echo $keywords->keyword_id; ?>"><?php echo $keywords->keyword_name; ?></option>  
<?php        }  
        }
    }
?> 

I am trying to do something like this i am getting values but the unsaved values which are comming from second is taking alot of time to load data its very slow can i know how to fix this .

<script type="text/javascript">
    $(document).ready(function() {
        $(".selectmultiple").select2();
    });
</script>

public function keyword_all()
{
    $this->db->select('*')->from('keywords');
    $query=$this->db->get();
    return $keyword = $query->result();
}

this is the model from which i am looping foreach($keyword as $key=>$keywords)

Upvotes: 1

Views: 1767

Answers (1)

DinosaurHunter
DinosaurHunter

Reputation: 692

I'm not sure if this solves your problem but this could make things a bit quicker - it's certainly a lot neater.

<?php 
    $cats = explode(',', $r['keyword_whomtoteach']);
    foreach($cats as $vald) {
        foreach($keyword as $key=>$keywords) { ?>                    
            <option value="<?php echo $keywords->keyword_id; ?>" <?=($vald == $keywords->keyword_id ? 'selected' : '')?> ><?php echo $keywords->keyword_name; ?></option> 
<?php   }
    }
?>

Upvotes: 1

Related Questions