Passing ID by modal parameter

Asked

Viewed 1,439 times

0

I have the following problem, I have a $Id PHP I need to receive it in modal to make a SELECT in the table, and search for information in the BD.

The button it sits on one page, and the modal on another, and I made the include to call the modal, when I click on the button it does not pass the $Id.

<button type="button" data-toggle="modal" data-target="#ModalDetalhes" data-id="<?php echo $Id; ?>">
    <img src="Imagens/Detalhes.png" width="36" height="20">
</button> 

I will try to post my line of code to show my problem:

Arquivo OrdermServico.php

<?php
include("All_Modals");
$Busca = mysql_query("SELECT * FROM OrdemServico WHERE Status ='$Status'", $con -> conexaoMysqlP()) or die (mysql_error());
    $ContCampos = mysql_num_rows($Busca);
        $Consulta = mysql_fetch_array($Busca);
?>
<?php
if($ContCampos > 0) {
    do {
?>
<table>
<tr>
<td width="130px"><?=$Consulta["Status"]?></td>
<td width="380px"><?=@$Consulta["LaudoTecnico"] ?></td>
<td width="115px" align="center">
aqui preciso pegar o $ID 
    <?php 
    $Id = $Consulta["id"];
     ?>
<a href="" data-target="#ModalDetalhes" data-toggle="modal">Abrir Modal</a>

    </td>
</tr> 
</table>    
<?php
}while ($Consulta = mysql_fetch_assoc($Busca));

}
?>

File All_modals.php

<div class="modal fade" id="ModalDetalhes" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
  <div class="modal-header">
    <?php
    //Aqui preciso receber a variavel php para usar no select

    echo $Id;
        // Seleciona tabela o id para editar, excluir ou etc
            $query_Recordset1 = sprintf("SELECT * FROM OrdemServico WHERE id = '$Id'", $con -> conexaoMysqlP()) or die (mysql_error());
                $Recordset1 = mysql_query($query_Recordset1);
                    $row_Recordset1 = mysql_fetch_assoc($Recordset1);

        <div class="form-inline">  
            <div class="form-group">
                <label>OS Detalhes</label>
            </div>     
<div class="modal-body">
<php //Aqui irei montar o restante do codigo php ?>
<div class="modal-footer">
            <input type="submit" class="btn btn-primary" name="BotaoEnviar">      
  </div>
</form>      
</div>
</div>
</div>
</div>  
  • Is it Bootstrap? That should work, are you passing the right variable? It has the same name? I saw above $id and then $Id. Sometimes things like that happen ;)

  • It is yes, No and direct no, the modal button I have on one page, and the modal on another, then I called with the include... the modal opens, but I can’t pass the value of $Id through the data-id="<? php echo $Id; ?>"

  • Is this what you want? http://jsfiddle.net/k7FC2/1440/

  • Show amigo, it worked, but I need a php variable, because I need to make a select in modal, type if possible in js o <input type="text" name="bookId" value=""/> were the variable, unfortunately I’m starting now and I’m layman with JS... and php dominate well already!

  • Use $_Session. And Zera when you finish the code.

  • @Jorgeb. your example worked partly, but in the modal display the id correctly, but I need the <input[name="bookId"> receive via php, for example: $id ='<input type="text" name="bookId" value="""/>';, but it doesn’t work rsrs, could you give me another help? Because there in the modal I will do one more select, to filter and display the data of this $Id. Thanks in advance!

Show 1 more comment

1 answer

1


Marcos,

To make this type of call I usually use a modal searching the URL remotely, so I already pass the parameter through the direct URL, as below:

<a data-target="#remoteModal" data-toggle="modal" href="http://www.site.com.br/arquivoRemoto.php?variavel=parametro" class="btn btn-nav active" type="button">
ABRIR MODAL
</a>
  • I tried friend, but in modal I can not receive her, I tried more will not, example: $Var = $_GET['variavel'].

  • Try to put a template online so I can help you, because it is very simple to pass the direct parameter through the url, or in the example that the friend, Jorge B commented with an example in jsfiddle if you want to recover by javascript.

  • Then try to save on a $_Session.

Browser other questions tagged

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