SELECT DEPENDENT PHP

0

I hope you can support me with this: What I want is to obtain the ID of the school that was selected in the SELECT and then depending on that, pull it in a variable and place it in my SQL QUERY, so that depending on what it appears the grade and section that was registered in that school.

          <div class="form-group">
            <label class="col-sm-2 control-label">Colegio</label>
            <div class="col-sm-5">
              <select class="chosen-select" name="cole_id" autocomplete="off" required>
                <option value="">Selecciona un Colegio</option>
                <?php  foreach ($all_colegios as $cole): ?>
                  <option value="<?php echo (int)$cole['cole_id'] ?>">
                    <?php echo $cole['cole_nombre']?></option>
                <?php endforeach; ?>
              </select>
            </div>
          </div>

          <div class="form-group">
            <label class="col-sm-2 control-label">Salon</label>
            <div class="col-sm-5">
              <select class="chosen-select" name="sal_id" autocomplete="off" required>
              <option value="">Selecciona un Salon</option>
               <?php  
               $all_salones = mysqli_query($mysqli,  "SELECT * FROM salones WHERE cole_id = 1");
               foreach ($all_salones as $sal): ?>
                  <option value="<?php echo (int)$sal['sal_id'] ?>">
                    <?php echo $sal['sal_grado'] . " " . $sal['sal_seccion']?></option>
                <?php endforeach; ?>
              </select>
            </div>
          </div> 
    
asked by CRISTHIAN ANTONIO VILLALOBOS C 19.07.2018 в 03:22
source

1 answer

0

You must put that code that you have of html inside a form and put a button like this:

     //formulario
     <form class="" action="accion.php" method="post">
      //formulario
       <div class="form-group">
        <label class="col-sm-2 control-label">Colegio</label>
        <div class="col-sm-5">
          <select class="chosen-select" name="cole_id" autocomplete="off" required>
            <option value="">Selecciona un Colegio</option>
            <?php  foreach ($all_colegios as $cole): ?>
              <option value="<?php echo (int)$cole['cole_id'] ?>">
                <?php echo $cole['cole_nombre']?></option>
            <?php endforeach; ?>
          </select>
        </div>
      </div>

      <div class="form-group">
        <label class="col-sm-2 control-label">Salon</label>
        <div class="col-sm-5">
          <select class="chosen-select" name="sal_id" autocomplete="off" required>
          <option value="">Selecciona un Salon</option>
           <?php  
           $all_salones = mysqli_query($mysqli,  "SELECT * FROM salones WHERE cole_id = 1");
           foreach ($all_salones as $sal): ?>
              <option value="<?php echo (int)$sal['sal_id'] ?>">
                <?php echo $sal['sal_grado'] . " " . $sal['sal_seccion']?></option>
            <?php endforeach; ?>
          </select></br>
          //boton
         <input type="button" name="" value="Seleccionar">
          //boton
        </div>
      </div> 
   </form>

Then create a file that has the extension .php for example we will create the file "accion.php" the name of this file must go in the action of the form as I showed you above

Then to receive the data you must put the following code in the php file

<?php

  $colegio = $_POST["col_id"];
  $salon = $_POST["sal_id"];

  echo $colegio;
  echo $salon;

?>

Already with this you bring the id of the school and the room and you can make your query according to the selected room or school

    
answered by 30.07.2018 в 20:00