Modal receiving data from the database

Asked

Viewed 299 times

0

my products page displays from the database all registered products as div below.

<?php

                    $id_up = $GET["id"];
                    require("funcoes/conexao.php");

                    $quantidade = 10;

                    $p = (isset($_GET['p'])) ? (int)$_GET['p']: 1;

                    $inicio = ($quantidade * $p) - $quantidade; 

                    $sql = mysql_query("SELECT * FROM produtos ORDER BY desc_produtos ASC LIMIT $inicio, $quantidade") or die (mysql_error());              

                    while ($res_sql = mysql_fetch_array($sql)) {

                        echo '

<div class="gallery-grid col-md-3">
  <a href="#modal"><img src="web/images/'.$res_sql["img_produtos"].'" alt=""> 
  <span>Clique e Veja Mais Informações do Produto</span></a>
   <h5>'.$res_sql["desc_produtos"].'</h5></br>
<div class="gallery-button" class="cd-trigger"><a href="#modal">Leia Mais</a></div>

I have a modal created that by clicking Read More or Click and see more product information already opening the Modal I want and this modal has the following code that is at the end of this product page.

<div id="modal">
    <div class="modal-content">
        <div class="header">
            <h2>Categoria</h2>
        </div>
        <div class="copy">
            <p>aqui pegaria as informações do produto no banco de dados.</p>
        </div>
        <div class="cf footer">
            <a href="#" class="btn">Close</a>
        </div>
    </div>
    <div class="overlay"></div>
</div>          

The question is how do I click on Read More or Click and see more product information opens this Modal, but with the product information that comes from the database?

  • Render the modal with the data already loaded, that is, the modal will already be with the data mounted but it will only be displayed when the modal is opened. Inside the div.copy.

  • I used ajax, jquery, when I needed to do something related. If you want, I can give an answer with jquery. But, in advance, you do an ajax pointing to the php page where your bank items are and in the callback you print in the modal

  • @fajuchem could indicate me as the best way to do because I do not know how I will do to take the product ID and present inside the modal because if I put to play the id in href it does not open the modal.

  • @VME all help is welcome yes, if you want to show me your way I can try to adapt my code and test. Thank you!

  • Okay, I understood your problem and the way I said above might not be the best way. As it will be a product listing would not be nice to have a modal for each product. What I would recommend you to do is create a modal and regardless of the product you click it will always open the same modal. And for the data to be loaded you add a javascript event for when the image is clicked to make an ajax to a page that returns the information.

  • You can put a data-id='valor" in href and do the data search in ajax, call by code and backend that can be in php, ai with the return you display in modal

  • I made an example that can help you solve the problem. http://jsfiddle.net/kxfgdzjL/12/

  • These two pieces of code that are on your question are on the same page?

  • Yes are on the same page @VME

Show 4 more comments

1 answer

0

Dude you need to pass the product id through the button that calls the modal, then receive this id in the modal, then you can work the rest of the information within this modal.

Browser other questions tagged

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