Pick up ID by Modal

Asked

Viewed 400 times

0

I made a modal so that it was possible to see the history of each client. I’m having a hard time pulling the cod_cliente to show their history.

Archive where Modal is:

<?php 
include ("Config.php");
$consulta = mysql_query("SELECT * FROM clientes ORDER BY nome;");
$total = mysql_num_rows($consulta);
?>


</head>
<body>



<div class="row">
<div class="col-md-10">
<div class="col-sm-offset-1">

<table class="table table-striped"> 

<tr>
<h1>
    <th>Opção </th>
    <th>Cliente</th>        
    <th>Celular</th>
    <th>Telefone</th>
    <th>Email</th>


   </h1>
</tr>


<?php
 while($l = mysql_fetch_array($consulta)) {
 $COD_CLIENTE = $l["COD_CLIENTE"];
 $NOME        = $l["NOME"];
 $CELULAR       = $l["CELULAR"];
 $TELEFONE       = $l["TELEFONE"];
 $EMAIL = $l["EMAIL"];


 echo "
   <tr>
    <td><a href=\"editar_cliente.php?COD_CLIENTE=$COD_CLIENTE\">[Editar]&nbsp;</a>
    <a href=\"excluir_cliente.php?COD_CLIENTE=$COD_CLIENTE\">&nbsp;[Excluir]&nbsp;</a> "; ?>

**<button onclick="$('#modal-container').load('historico.php?COD_CLIENTE<?=$COD_CLIENTE?>', function(){$('#modal').modal('show');})">Histórico</button>
<div id="modal-container"></div>**


    </td>
    <td>&nbsp;$NOME</td>
    <td>&nbsp;$CELULAR</td>
    <td>&nbsp;$TELEFONE</td>
    <td>&nbsp;$EMAIL</td>
</tr>\n";
}

?>

</table>



</div>
</div>
</div>


 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js">
 </script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="C:\xampp\htdocs\SALAO\bootstrap/js/bootstrap.min.js"></script>
<script src="C:\xampp\htdocs\SALAO\bootstrap/js/bootstrap.js"></script>
<script src='http://code.jquery.com/jquery-2.1.3.min.js'></script>
<script src='//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js'>
</script>

<!-- necessary scripts for the dialog -->
<link rel="stylesheet" 
href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script 
src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js">

This is the historical file.php:

  <?php
  $COD_CLIENTE = $_GET["COD_CLIENTE"];

   include ("Config.php");


   $re2    = mysql_query("SELECT salao.clientes.NOME 'cliente_nome', salao.procedimentos.NOME, salao.agenda.DATA

                    FROM salao.agenda

                    INNER JOIN procedimentos ON procedimentos.COD_PROCEDIMENTOS = agenda.COD_PROCEDIMENTOS

                    INNER JOIN clientes ON clientes.COD_CLIENTE = agenda.COD_CLIENTE

                    where clientes.COD_CLIENTE = $COD_CLIENTE
                    ORDER BY agenda.data");


$total2 = mysql_num_rows($re2);

   ?>

   <div class="modal fade" id="modal" tabindex="-1" role="dialog">
   <div class="modal-dialog">
    <div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal">&times;
</button>
            <h4 class="modal-title">Histórico</h4>
        </div>
        <div class="modal-body">

                <div class="row">
                <div class="col-md-10">
                <div class="col-sm-offset-1">

                    <table id= "contact_form" class="table table-striped"> 
                        <tr>

                        <th>Procedimentos</th>
                        <th>Data</th>

                        </tr>

                    <?php
                    while($l2 = mysql_fetch_array($re2)) {
                      $procedimentos       = $l2[1];
                      $data       = $l2["DATA"];

                    echo "
                      <tr>

                        <td>&nbsp;$procedimentos</td>
                        <td> "; 
                            echo date('d/m/Y', strtotime($data));
                    echo "
                        </td>
                      </tr>\n";

                    } 

                    ?>  

                    </table>

                </div>
                </div>
                </div>
        </div>
    </div>
   </div>
   </div>



 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js">
</script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="C:\xampp\htdocs\SALAO\bootstrap/js/bootstrap.min.js"></script>
<script src="C:\xampp\htdocs\SALAO\bootstrap/js/bootstrap.js"></script>
<script src='http://code.jquery.com/jquery-2.1.3.min.js'></script>
<script src='//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js'>
 </script>
<!-- necessary scripts for the dialog -->
<link rel="stylesheet" 
href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js">
</script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js">
</script>

 </body>
</html>
  • From what I understand, you used $COD_CLIENTE directly in the HTML inside the tag button. To display the value, you need to include this variable between PHP tags: <?= $COD_CLIENTE ?>. Try it and tell me what happened.

  • Hello Anderson, I did what you told me but unfortunately it didn’t work... he didn’t take the cod_client. Do you any other tip to give me? Thank you very much!!

  • In the archive historico.php, if you stay var_dump($_GET['COD_CLIENTE']), what is the result?

  • These are errors that appear due to not finding the cod_client... string(12) "$COD_CLIENTE" Notice: Undefined variable: COD_CLIENTE in C: xampp htdocs SALAO historico.php on line 7 Notice: Undefined variable: COD_CLIENTE in C: xampp htdocs SALAO historico.php on line 21 Warning: mysql_num_rows() expects Parameter 1 to be Resource, Boolean Given in C: xampp htdocs SALAO historico.php on line 24

  • If it’s a mistake, why didn’t you already say that in the question and post the messages? Is it possible to [Edit] the question and add how you tried to implement my first tip? Take advantage and put the file code historico.php.

  • I put the historical file.php in the question... I did not put the errors because I thought it would not be necessary because I know that the errors are due to the file not catch the cod_client. I put your first tip there.

  • Understand that it’s not <?php= ... ?>, but yes <?=...?>, without the php. You can read about their difference here.

  • I tried both ways but it didn’t work anyway...

  • What is the HTML generated from this PHP file that has the modal?

  • I don’t know if I got your question right, but I’m only using these two files... the.php client list (which is where the modal is) and the historical.php that I call when I click on "History".

  • The Andersson request is to show the HTML that appears in the browser, ie PHP compiled.

Show 6 more comments
No answers

Browser other questions tagged

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