Fill modal with PHP Bd data

Asked

Viewed 2,000 times

1

I’m having trouble filling a modal with data coming from an sql query.

I have a list of all the products. In this list I have a button that when clicked should open a modal with the product details.

Knob:

<button type="button" class="btn btn-primary btn-mini" data-toggle="modal" onclick="detalhesProduto(' + retorno[i].id + ')">+ Detalhes</button>

This button passes the product id to Function below:

function detalhesProduto(id) {
    alert(id);
    $('#myModal').modal('show');        
}

In this case, I have another Function that connects and scans the bank , where I get the product id.

The way it is there, I click on the button opens a dialog with the id of the product selected, soon after opens the dialog, but I do not know how to fill it with the data... that in this case, if you filled at least the id I already had the rest.

My modal is like this:

<div class="modal fade bs-detalhes-modal-lg" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
        <div class="modal-dialog modal-lg">
            <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>
                    <h5 class="modal-title" id="myModalLabel">Detalhes</h5>
                </div>
                <div class="modal-body" id="conteudoModal">
                   .............. 
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default btn-mini" data-dismiss="modal">Fechar</button>                        
                </div>
            </div>
        </div>
    </div>

Could you give me a hand with that?

  • I didn’t understand this part: "The way it is there, I click on the button opens a dialog with the id of the selected product, then opens the dialog"

  • @Lucas is that when I click the button, I’m already getting the product ID ... and this ID I put on an Alert to see if it was changing as I click on another product from my list. That is, the dialog or modal... opens... just do not know how to take the product data and put in this modal.

  • Um yes. Would have to do in Ajax

  • Got it, and how would I do it? I have an ajax that searches all my products and fills the list I mentioned. I took some examples on the net and could not succeed in filling the modal.

1 answer

1


Solved:

function detalhesProduto(id) {
    $('#myModal').modal('show');
    $("#conteudoModal").load('detalhaProduto.php?id=' + id);
}
  • Good. Mark this answer as sure then (by clicking on the check next to the answer)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.