dimanche 17 novembre 2019

Dynamic check the check box if value is there in DB

DB has the value of few India states in this format:

Goa, Karnataka, Andhra Pradesh, Arunachal Pradesh, Chattisgarh

I am trying to add edit feature to change the states option to DB:

When I open edit page:

I have created list of state in a checkbox:

        <label class="checkbox-inline"><input type="checkbox" value="">Andhra Pradesh</label>
        <label class="checkbox-inline"><input type="checkbox" value="">Arunachal Pradesh</label>
        <label class="checkbox-inline"><input type="checkbox" value="">Assam</label>
        <label class="checkbox-inline"><input type="checkbox" value="">Bihar</label>
        <label class="checkbox-inline"><input type="checkbox" value="">Chhattisgarh</label>
        <label class="checkbox-inline"><input type="checkbox" value="">Goa</label>
        <label class="checkbox-inline"><input type="checkbox" value="">Gujarat</label>
        <label class="checkbox-inline"><input type="checkbox" value="">Haryana</label>
        <label class="checkbox-inline"><input type="checkbox" value="">Himachal Pradesh</label>
        <label class="checkbox-inline"><input type="checkbox" value="">Jammu and Kashmir</label>
        <label class="checkbox-inline"><input type="checkbox" value="">Jharkhand</label>
        <label class="checkbox-inline"><input type="checkbox" value="">Karnataka</label>
        <label class="checkbox-inline"><input type="checkbox" value="">Kerala</label>

Now I want to check the value is available in DB if so checkbox should be checked.

So what I did I split the value from db:

 $return = '';
 $string = $zone_state; //db value
 $values = str_getcsv($string);
 foreach($values as $key => $value)
 {
   if($key >= 0) {
    $return .= trim($value);    
   }
 }

   echo $return;

$returns value without "," - GoaKarnatakaAndhra PradeshArunachal PradeshChattisgarh

I didn't know how to check $return value with checkbox?

Can someone help me with this?

Thanks!




Aucun commentaire:

Enregistrer un commentaire