Problem with modal and php query

0

My doubt is as follows I have this code where I consult information and create an arrangement, when I click on a detail button I get a post file that brings me the idweb value of that row, besides opening a modal that should contain the query data but when I perform this process I get the modal without data

    <?php 
    $tour="";
    $adultos="";
    $ninos="";
    $fecha="";
    $hora="";
    $hotel="";
    $observaciones="";
    $precio="";
    $idweb="0";
    if (isset($_POST["idweb2"])) //esta es una variable que obtengo cuando se le 
    da click a una fila de tabla {
    $idweb = $_POST["idweb2"];
    require_once("../_clases/class-mysqli.php");
    $instance = new Conexion();
    $conexion = $instance->Conect();

     $consulta='SELECT * FROM tbldetalle WHERE idweb='.$idweb.'';
     $resultado = $conexion->query($consulta);

      while($datos=$resultado->fetch_array()){

             $tour2=$datos["tour"];
             $adultos2=$datos["adultos"];
             $ninos2=$datos["ninos"]; 
             $fecha2=$datos["fecha"];
             $hora2=$datos["hora"];
             $hotel2=$datos["hotel"];
             $observaciones2=$datos["observaciones"];
             $precio2=$datos["precio"];


          }

          }    


         echo "<script>$(document).ready(function(){ 
         $('#myModal').modal('show'); 
         });</script>

            <div class='modal fade' id='myModal' tabindex='-1' role='dialog' 
             aria-labelledby='myModalLabel'>
            <div class='modal-dialog' role='document'>
            <div class='modal-content'>
            <div class='modal-header'>
            <button type='button' class='close' data-dismiss='modal' aria- 
            label='Close'><span aria-hidden='true'>&times;</span></button>
            <h4 class='modal-title text-center'  id='myModalLabel'>Detalle de la 
            Reserva</h4>
            </div>
           <div class='modal-body'>

            <div class='table-responsive'>  
             <table class='table table-bordered'>
                <tr>  
                     <td  style='background-color:var(--dark-primary- 
              color);color:white' width='30%'><label>Tour</label></td>  
                     <td width='70%''>".$tour2."</td>  
                </tr>  
                <tr>  
                     <td style='background-color:var(--dark-primary- 
              color);color:white' width='30%''><label>Adultos</label></td>  
                     <td width='70%''>".$adultos2."</td>  
                </tr>  
                <tr>  
                     <td style='background-color:var(--dark-primary-color);color:white' width='30%'><label>Niños</label></td>  
                     <td width='70%'>".$ninos2."</td>  
                </tr>  
                <tr>  
                     <td style='background-color:var(--dark-primary-color);color:white' width='30%'><label>Fecha operación</label></td>  
                     <td width='70%'>".$fecha2."</td>  
                </tr>  
                <tr>  
                     <td style='background-color:var(--dark-primary-color);color:white' width='30%'><label>Hora</label></td>  
                     <td width='70%'>".$hora2."</td>  
                </tr>  

                <tr>  
                     <td style='background-color:var(--dark-primary-color);color:white' width='30%'><label>Hotel</label></td>  
                     <td width='70%'>".$hotel2."</td>  
                </tr>  

                 <tr>  
                     <td style='background-color:var(--dark-primary-color);color:white' width='30%'><label>Observaciones</label></td>  
                     <td width='70%'>".$observaciones2."</td>  
                </tr>  
                 <tr>  
                     <td style='background-color:var(--dark-primary-color);color:white' width='30%'><label>Precio</label></td>  
                     <td width='70%'>".$precio2."</td>  
                </tr>  

           </table>  
      </div>  

      </div>

    </div>
  </div>
</div>
        ";   


        ?>

Sorry to come out like this but it's the first time I insert code thank you very much for the help

    
asked by crije 09.08.2018 в 16:57
source

1 answer

0

You have to put the exit code inside the while , now your code goes through the loop and then paints the html, when leaving the loop it should not have data.

Your code would look like this:

    <?php 
    $tour="";
    $adultos="";
    $ninos="";
    $fecha="";
    $hora="";
    $hotel="";
    $observaciones="";
    $precio="";
    $idweb="0";
    if (isset($_POST["idweb2"])) //esta es una variable que obtengo cuando se le 
    da click a una fila de tabla {
    $idweb = $_POST["idweb2"];
    require_once("../_clases/class-mysqli.php");
    $instance = new Conexion();
    $conexion = $instance->Conect();

     $consulta='SELECT * FROM tbldetalle WHERE idweb='.$idweb.'';
     $resultado = $conexion->query($consulta);

      while($datos=$resultado->fetch_array()){

             $tour2=$datos["tour"];
             $adultos2=$datos["adultos"];
             $ninos2=$datos["ninos"]; 
             $fecha2=$datos["fecha"];
             $hora2=$datos["hora"];
             $hotel2=$datos["hotel"];
             $observaciones2=$datos["observaciones"];
             $precio2=$datos["precio"];
echo "<script>$(document).ready(function(){ 
         $('#myModal').modal('show'); 
         });</script>

            <div class='modal fade' id='myModal' tabindex='-1' role='dialog' 
             aria-labelledby='myModalLabel'>
            <div class='modal-dialog' role='document'>
            <div class='modal-content'>
            <div class='modal-header'>
            <button type='button' class='close' data-dismiss='modal' aria- 
            label='Close'><span aria-hidden='true'>&times;</span></button>
            <h4 class='modal-title text-center'  id='myModalLabel'>Detalle de la 
            Reserva</h4>
            </div>
           <div class='modal-body'>

            <div class='table-responsive'>  
             <table class='table table-bordered'>
                <tr>  
                     <td  style='background-color:var(--dark-primary- 
              color);color:white' width='30%'><label>Tour</label></td>  
                     <td width='70%''>".$tour2."</td>  
                </tr>  
                <tr>  
                     <td style='background-color:var(--dark-primary- 
              color);color:white' width='30%''><label>Adultos</label></td>  
                     <td width='70%''>".$adultos2."</td>  
                </tr>  
                <tr>  
                     <td style='background-color:var(--dark-primary-color);color:white' width='30%'><label>Niños</label></td>  
                     <td width='70%'>".$ninos2."</td>  
                </tr>  
                <tr>  
                     <td style='background-color:var(--dark-primary-color);color:white' width='30%'><label>Fecha operación</label></td>  
                     <td width='70%'>".$fecha2."</td>  
                </tr>  
                <tr>  
                     <td style='background-color:var(--dark-primary-color);color:white' width='30%'><label>Hora</label></td>  
                     <td width='70%'>".$hora2."</td>  
                </tr>  

                <tr>  
                     <td style='background-color:var(--dark-primary-color);color:white' width='30%'><label>Hotel</label></td>  
                     <td width='70%'>".$hotel2."</td>  
                </tr>  

                 <tr>  
                     <td style='background-color:var(--dark-primary-color);color:white' width='30%'><label>Observaciones</label></td>  
                     <td width='70%'>".$observaciones2."</td>  
                </tr>  
                 <tr>  
                     <td style='background-color:var(--dark-primary-color);color:white' width='30%'><label>Precio</label></td>  
                     <td width='70%'>".$precio2."</td>  
                </tr>  

           </table>  
      </div>  

      </div>

    </div>
  </div>
</div>
        ";   

          }

          }    



        ?>
    
answered by 09.08.2018 в 17:07