mardi 18 octobre 2016

how to show multiple selected values using responce

I am trying to achieve show already stored values as selected.

my question is i am trying to fetch multiple facilitites from mapping table that is os_hostel_facility but when i try to show that only first value is coming in console even that is not showing as selected how can i do that my code is at bottom:

Please suggest edit if question does not reach standards..!

This the image of os_hostel table

enter image description here

form of update

This is my script:

   success: function (response) {
    $("#viewhostelfacility").val(response['facility']['id_facility']);
    console.log(response['facility']['id_facility']); 

here only first value is coming and i want to show the whole array as selected

This is my update form code

<ul id="hostel_facility" class="dropdown-menu dropdown-select">
    <?php  $facility = $conn->query("SELECT * FROM os_facilities  ORDER BY id_facility ASC");
        while ($facilityresult = $facility->fetch_assoc()) { ?>
        <li><a><input type="checkbox" name="hostel_facility[]" id="viewhostelfacility" value="<?php  echo $facilityresult['id_facility']; ?>" /><?php echo $facilityresult['facility_name']; ?></a></li>
    <?php } ?>
</ul>

And this my controller page from where i am sending ersponse:

$facilitysearch= $conn->query("SELECT * From os_hostel_facility WHERE id_hostel='".$_POST['hostelId']."'") or die(mysql_error());
$viewfacility=$facilitysearch->fetch_assoc();
$response['facility'] = $viewfacility;




Aucun commentaire:

Enregistrer un commentaire