Open a Modal with the result of MySql

2

And the beauty galley? I'm studying Dev Web and I'm creating a pro-boot system with customer records and reports.

Let's doubt it. I have a report page and there I have an input type="date" inside a form that will do the fetching from a date in the database:

        <!-- BUSCA CALENDARIO -->        
        <div class="col-sm-offset-4 col-sm-4">
        <!-- Input ao qual foi designado a função para exibir o calendário, que vai ser selecionado com jquery na função abaixo. -->
            <input type="date" id="busca_data" name="busca_data" placeholder="data" class="form-control">
        </div>
        <button class="btn btn-info" id="btn_buscar" type="submit">Buscar</button>

The file that I send this post is the search_relatorio.php that has this code:

$id_usuario = $_SESSION['id_usuario'];
$empresa_logada = $_SESSION['empresa']; 
$busca_data = $data = str_replace("/", "-", $_POST['busca_data']);

$objDb = new db();
$link = $objDb->conecta_mysql();

$sql = " SELECT DATE_FORMAT(s.data_relatorio, '%d %b %Y') ";
$sql.= " AS data_relatorio_formatada, s.relatorio, u.usuario FROM relatorios AS s JOIN usuarios AS u ON ";
$sql.= " (s.id_usuario = u.id) WHERE nivel = 3 AND s.empresa = '$empresa_logada' ";
$sql.= " ORDER BY data_relatorio DESC ";


$resultado_id = mysqli_query($link, $sql);

if($resultado_id){

    while ($registro = mysqli_fetch_array($resultado_id, MYSQLI_ASSOC)){            
        $relatorios = $registro;
        echo '<pre>'.$registro['relatorio'].'</pre>';

    }

} else {
    echo 'Erro na consulta de tweets no banco de dados!';
}

This echo $ record ['report'] was a test I was doing.

Well what I can not do is open a Modal within the Reports page itself where only this result of the database comes from. I imagine I need to do this via Ajax however in my code I could not open the modal. I have already created a function after document.ready to be able to load this report but it only works by taking me to another page.

What I've been doing via jquery is this:

$('#btn_buscar').click( function(){                 
                $.ajax({
                    url:'busca_relatorio.php',
                    method: 'post',
                    data: $('#resultado_busca').serialize(),
                    sucess: function(data){                         
                        $('#resultado_busca').val('');
                    }
                });
            });

At the bottom of my page is a div to show this:

<div class="panel-body" id="resultado_busca"></div>

But I just wanted to show this result within a modal. Can someone help me with this headache? kkkkkk

Thank you guys.

    
asked by anonymous 01.08.2017 / 23:48

1 answer

0

As you know, you're using Bootstrap, by following this one, add the following code in your HTML page where AJAX is loaded:

<div class="modal fade" id="exampleModalLong" tabindex="-1" role="dialog" aria-labelledby="exampleModalLongTitle" aria-hidden="true">
  <div id="resultado_busca">...</div>
</div>

Within the success of your Ajax add:

$('#resultado_busca').html(data); // data é o valor printado do lado php
$('#exampleModalLong').modal('show') ; // abre o modal via jquery

Just one note: success is with two C's and two S's

EDIT This is the modal documentation on the Bootstrap site, it's worth taking a look also: link

    
02.08.2017 / 17:30