Pass modal window id

Asked

Viewed 1,224 times

0

I’m not getting an id to a modal window. Could you help me?

The excerpt from the main page code is this:

php menu.

$id= $_GET["id"];
<div style="text-align: center"><a href="#pagina1" class="btn_modal">
                <h3>VER MAIS</h3></a></div>
            <div id="modal">
                <div class="box-modal">
                    <div class="box-modal-load"></div>  
                    <div class="fechar">X</div>
            </div> 
</div>

This is the script that runs:

php menu.

<html>
<script type="text/javascript">
    $(document).ready(function(e) {
        $('.btn_modal').click(function(e){
            e.preventDefault();
            var url = $(this).attr('href')
            $('.box-modal-load').load("pagina.php "+url);
            $('#modal').fadeIn(500);    
        });
        $('#modal, .fechar').click(function(e){
            if( e.target !== this ) 
                return;
            $('#modal').fadeOut(500);   
        });
        });
 </script>
</html>

This is the modal window

php page.

<?php


$id = $_GET["id"];
$query4 = "SELECT 
*
FROM
tabela
WHERE
idpessoa = $id";
$resultado4 = consultaQuery4($query4);

function consultaQuery4($query4)
{
include_once 'conexao2.php';
$consultaQuery4 = mysqli_query($connect, $query4);
return $consultaQuery4;
}

?>
<div id="pagina1">
    <h1>Avaliações</h1>
    <div class="avaliacaomodal">
        <table class="table2modal">
            <thead>
                <tr>
                </tr>
            </thead>
            <tbody class="cptabelaavamodal">
                <?php while($ava = mysqli_fetch_array($resultado4)):?>
                    <tr class="registrosavamodal">
                        <td id="imgusermodal"><img src='<?php echo $ava['imagem'];?>'  width="100" height="100"><?php echo nl2br ("<h7>".$ava['nome']."\n".$ava['data']."</h7>");?></td>
                        <td id="tabelaavamodal"><?php echo nl2br ("<h4>".$ava['comentario']."</h4>"."\n\n"."<h3>".$ava['nomeret']."\n".$ava['replica']."</h3>");?></td>
                        <td id="colunanotamodal"><?php echo nl2br ("<h1>".$ava['nota']."</h1>");?></td>
                    </tr>
                <?php endwhile;?>
            </tbody>
        </table> 
    </div>
  • Who ID do you want to pass ? Can’t understand your question.

  • Sorry Wellington, I had forgotten to put rs. I was already editing. This id is a key to a query in the database that is already present in the menu page.php

  • I reduced the code, but the main part is this. Where I click on the link "See more" and goes to the modal window (page.php). I did a test replacing the $id on the modal page with a bank id and the code worked. The biggest problem is passing this parameter.

  • You could do it like this <a href="?id=<?php echo $_GET["id"]; ?>#pagina1" class="btn_modal"> in the archive menu.php, also take a space that has in .load("pagina.php "+url) leaves so .load("pagina.php"+url)

  • Bro, ball show. What you gave me gave certin. Thank you so much! God bless

2 answers

1


You could do it like this

<a href="?id=<?php echo $_GET["id"]; ?>#pagina1" class="btn_modal">

in the archive php menu., also take a space that has in

.load("pagina.php "+url)

leaves so

.load("pagina.php"+url)

0

Created one the following way First I made mine PHP, and called the page where the modal was on the button (In the case to edit). With the id of my variable that in the case is this excerpt

<a href="editar/editarnovidades.php?id_img=<?php echo $rs['id_img']; ?>" ...

Code below I hope it helps.

<div class="container-fluid">
<?php 
include('conect.php');
$consulta = "SELECT * FROM novidade";
$cons = mysqli_query($conect_phpmyadmin,$consulta);
while ($rs = mysqli_fetch_array($cons))
    {
        $nome = $rs['nome_img'];
        $desc = $rs['descprod_imagem'];
        $imagem = "uploads/".$rs['desc_img'];
?>
<div class="col-sm-6 col-md-4">
    <div class="thumbnail">
        <img src="<?php echo $imagem;?>" alt="Produto da loja" width="275" heigth="150">
        <div class="caption">
            <h3><?php echo $nome; ?></h3>
        </div>
        <p><?php echo $desc; ?></p>
        <p><a href="editar/editarnovidades.php?id_img=<?php echo $rs['id_img']; ?>" data-toggle="modal" data-target="#myModal" class="btn btn-primary" role="button">Editar</a> 
        <a href="excluir/excluircheck.php?id_img=<?php echo $rs['id_img']; ?>" data-toggle="modal" data-target="#myModal" class="btn btn-default" role="button"
        onclick="return confirm('Deseja excluir o produto?');">Apagar</a></p>
        <div class="modal fade" id="myModal" role="dialog">
            <div class="modal-dialog">      
            <div class="modal-content">
            </div>
            </div>
        </div>
    </div>
</div>
<?php } ?>
</div>
  • Edith your answer, and format the code, select all of it and press CTRL+K

Browser other questions tagged

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