Welcome Guest, Not a member yet? Register   Sign In
Explode for selected
#1

Hi all,

I have trouble on this code,

In DB "planCurrencies" = "1,2,3,4"
PHP Code:
<select class="select2" name="currency[]" style="width: 100%" multiple="multiple" data-placeholder="Choose">
    <?
php
    $cid 
explode(',',$plan->planCurrencies);
    foreach(
$this->currencies_model->get() as $c) { ?>
    <option value="<?php echo $c->ID?><?php echo $c->ID == $cid "selected":"" ?>><?php echo $c->currencyCode?></option>
    <?php ?>
</select> 

This code already show all currencies but selected currency not working,

Thanks you
Reply
#2

$cid is array in your case, so the <option> selected will be like this

Code:
<option value="<?php echo $c->ID; ?>" <?php echo in_array($c->ID, $cid) ? "selected":"" ?>><?php echo $c->currencyCode; ?></option>


I hope this works for you
Reply
#3

(11-06-2017, 10:43 PM)pravins Wrote: $cid is array in your case, so the <option> selected will be like this

Code:
<option value="<?php echo $c->ID; ?>" <?php echo in_array($c->ID, $cid) ? "selected":"" ?>><?php echo $c->currencyCode; ?></option>


I hope this works for you

Oh man!! it's really work! Thanks you so much!!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB