how to nest 2 records of the same table

0

Hi, I have a query, I have a table of courses where cod_curso, cod_ramo, section and name. what I have is a search engine (autocomplete) of the name of the course that is good for me, but what I need at the time of finding the course I enable all sections of the course, for example I look for the CALCULATE I course and I would have to enable a combobox with all sections (1,2,3,4,5,6)

 <?php
    require("conexion.php")
?>
<!DOCTYPE html>
<html>
 <head>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-3-typeahead/4.0.2/bootstrap3-typeahead.min.js"></script>  
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />  
 </head>
 <body>
  <br /><br />
  <form action="" method="post">
  <div class="container" style="width:600px;">
   <br /><br />
   
   <div class="form-group">
       <label for="sel1">Seleccione año de ingreso:</label>
           <select class="form-control" name="anio_ingreso" id="ua" placeholder="Ingrese unidad academica">
            <?php
                            
            $query = $mysqli -> query ("SELECT DISTINCT anio_ingreso FROM 'alumnos' ORDER BY 'anio_ingreso' ASC");
											
            while ($valores = mysqli_fetch_array($query)) {
												
            echo '<option value="">'.$valores[anio_ingreso].'</option>';
													
            }
    
            ?> 
      
           </select>
   </div>
   <div class="form-group">
   <label for="sel1">Seleccione unidad acamdemica:</label>
   <select class="form-control" name="ua" id="ua" placeholder="Ingrese unidad academica">
        <?php
                            
        $query = $mysqli -> query ("SELECT DISTINCT ua FROM 'alumnos' ORDER BY 'ua' ASC");
											
         while ($valores = mysqli_fetch_array($query)) {
												
         echo '<option value="'.$valores[ua].'">'.$valores[ua].'</option>';
													
         }
    
        ?> 
      
   </select>
   </div>
   <br>
   
   <div class="form-group">
   <label>Seleccione Asignatura:</label>
   <input type="text" name="cursos" id="cursos" class="form-control" autocomplete="off" placeholder="" />
    
   </div>
   
   <div class="form-group">
   <label>Seleccione Seccion:</label>
    <select class="form-control" name="seccion" id="seccion" placeholder="Ingrese unidad academica">
        <?php
                            
        $query = $mysqli -> query ("SELECT seccion FROM 'cursos' WHERE nombre = '?????' ORDER BY 'seccion' ASC");
											
         while ($valores = mysqli_fetch_array($query)) {
												
         echo '<option value="'.$valores[seccion].'">'.$valores[seccion].'</option>';
													
         }
    
        ?> 
      
   </select>
   </div>
   
   <div class="form-group">
       <label for="sel1">Seleccione año:</label>
           <select class="form-control" name="" id="" placeholder="">
              <option value=2016>2016 
              <option value=2017>2017 
              <option value=2018>2018 
              <option value=2019>2019 
      
           </select>
   </div>
   
   <div class="form-group">
       <label for="sel1">Seleccione semestre:</label>
           <select class="form-control" name="" id="" placeholder="">
              <option value=Primer>Primer 
              <option value=Segundo>Segundo

      
           </select>
   </div>
   
   
   </div>
  </form>
 </body>
</html>

<script>
$(document).ready(function(){
 
 $('#cursos').typeahead({
  source: function(query, result)
  {
   $.ajax({
    url:"fetch.php",
    method:"POST",
    data:{query:query},
    dataType:"json",
    success:function(data)
    {
     result($.map(data, function(item){
      return item;
     }));
    }
   })
  }
 });
 
});
</script>

<?php

$connect = mysqli_connect("localhost", "root", "", "encuesta1");
$request = mysqli_real_escape_string($connect, $_POST["query"]);
$request = htmlspecialchars($request);
$query = "SELECT * FROM cursos WHERE nombre  LIKE '".$request."%' LIMIT 5";

$result = mysqli_query($connect, $query);

$data = array();

if(mysqli_num_rows($result) > 0)
{
 while($row = mysqli_fetch_assoc($result))
 {
  $data[] = $row["nombre"];
 }
 echo json_encode($data);
}

?>

any help or guidance will be welcome

    
asked by claudia24 23.10.2017 в 22:01
source

0 answers