show mysql query with javascript php checkbox

0

Good afternoon I have a code in php where a list has values of a mysql field:

<div class="input-group">
     <span class="input-group-addon">Ruta: </span>
      <select name="rutas" id="estados" value="0" class="form-control" onchange="showUser(this.value)">
        <?php
          while ($fil = mysqli_fetch_array($resultas)){  ?>

            <option value="<?php echo $fil['id']; ?>"><?php echo $fil['descripcion']; ?></option>

          <?php 
        } ?>
        </select>
      <span class="input-group-btn">
      <a href="rutas/nuevaRuta.php" class="btn btn-success" role="button"><span class="glyphicon glyphicon-plus-sign"></span></a>
  </span>
  </div>

Where the data comes from the following query:

 $resultas = mysqli_query($link, "SELECT * FROM rutas WHERE (cveorig='$claveEstado' OR cvedest='$claveEstado') AND cliente='CLI140002'");

What I need is to make a general query (show all the records in the description field) by clicking on a checkbox

    
asked by Jose Luis GP 27.03.2017 в 21:41
source

1 answer

0

If I understand your problem well is that you do not know how to update the query sql when activating checkbox , if so, I recommend using JS or Jquery and load the data asynchronously, ie , instead of this:

<select name="rutas" id="estados" value="0" class="form-control" onchange="showUser(this.value)">
    <?php
      while ($fil = mysqli_fetch_array($resultas)){  ?>
        <option value="<?php echo $fil['id']; ?>"><?php echo $fil['descripcion']; ?></option>
      <?php 
    } ?>
</select>

Try loading for example with jquery :

$('#id_checkbox').change(function () {
  $.post(url_backend, params)
   .done(function (data) {
     //recorrer el resultado, recomendado retornar json desde el server
     $.each(data, function(i, item) {
       $('#estados').append($('<option>', {
         value: item.value,
         text: item.text
       }));
     });
   });
}

And repeat this when you load the dom to load the first query of select .

Edit : Remember to reset the select because the append adds the element to the end of the content of select .

    
answered by 28.03.2017 / 07:16
source