Datatable in PHP mysql modal

0

Hi, I have 2 problems, the first one corresponds to the fact that I load the data of a query to mysql in a table, the table is in a boostrap modal, but it does not load the table as datatable but as a common table without the possibility that can be sorted by column and without vertical scroll.

The second problem is that when I make the query to bring the data by clicking on the boto list it takes me out of the modal and returns me to the page and I have to re-enter the modal to see the already loaded query I add the modal code

<!-- modal form buscar -->

                       Search for mobile                    ×                                                                                  Select Area                                                                                                                                                                PUBLIC SERVICES                                                       GREEN AREAS                                                       MUNICIPAL WORKS                                                       PRIVATE WORKS                                                       AUTOMOTIVE PARK                                                       SECURITY                                                   

    </div>
    <div class="col-md-3">
      <h2></h2>
    <button type="submit" id="listar" name="listar" class="btn btn-primary">Listar móviles</button>
  </div>
  </div>

      <div class="form-group">
        <label for="message-text" class="col-form-label">Móviles:</label>
         <table id="sampleTable2" class="table table-hover table-bordered display nowrap" cellspacing="0">


                                <thead >
                                   <tr>                                            
                                        <th>Patente</th>
                                        <th>Area</th>
                                        <th>Interno </th>
                                        <th>Marca</th>


                                    </tr>
                                </thead>
                                  <tbody>
                                    {height: 100px;
                                    overflow-y: auto;    
                                    overflow-x: hidden;}
                                  <?php
                                  while($row2 = mysqli_fetch_array($resultado))
                                    {
                                      echo '
                                      <tr>
                                      <td>'.$row2["Patente"].'</td>
                                      <td>'.$row2["Area_Responsable"].'</td>
                                      <td>'.$row2["Interno"].'</td>
                                      <td>'.$row2["Marca"].'</td>
                                      </tr> ';

                                    }
                                    mysqli_free_result($resultado)



                                 ?>
                                </tbody>
                                 <tfoot>
                                    <tr>
                                        <th>Patente</th>
                                        <th>Area</th>
                                        <th>Interno</th>
                                        <th>Marca</th>
                                    </tr>                                


                                </tfoot>



                            </table>
      </div>
    </form>
  </div>
  <div class="modal-footer">
    <button type="button" class="btn btn-secondary" data-dismiss="modal">Cerrar</button>
    <button type="button" class="btn btn-primary">Seleccionar</button>
  </div>
</div>

The query works and is done in php I add part of the code

    $conn = mysqli_connect("localhost", "root", "", "movedb"); 
if(isset($_POST['listar']))
{
  $area = $_POST['area2'];
  if(!is_null($area)){
    $resultado= mysqli_query($conn,"SELECT Patente, Marca, Modelo, Tipo, Interno, Area_Responsable FROM moviles, areas where areas.Area_Responsable ='$area' and moviles.Id_Area = areas.Id_Area");




  }
    
asked by Julio 12.07.2018 в 15:30
source

1 answer

0

The second problem may be the way you have defined the modal bootstrap window. add the following code when loading the DOM.

script...>

document.addEventListener('DOMContentLoaded', () => {
        $('#idVentanaModal').modal({
            keyboard: false,
            backdrop: 'static',
            show: true
        });
});

si show es false, para mostrarla, en la funcion...
$('#idVentanaModal').modal('show');
    
answered by 12.07.2018 в 15:51