Pass PHP ID to Modal Jquery Window

-3

I need to finalize an urgent project and there is something I need to do and I have no idea how it is done. I am doing a student registration system, where I will search by name, cpf or class schedule.

All search methods will be non-exact searches, meaning that it will bring me more than one database result. I want you to click on the name of who appeared, open a Jquery modal window with that person's complete data to be edited or added one more or another. I will apply this to other parts of the system and need it urgently to continue.

I separated and recorded a video presenting the problem and presenting the system a bit, follow the link on youtube: link

Follow my PHP Full:

    <!-- Modal Avisos -->    
        <div id="boxes">
            <div id="dialog" class="window">
              <div class="title-modals"> <div class="img_warm"> </div> <h3> Aviso </h3></div>
              <div class="cont-modal">
                <?php 
                    if($acao == "search_name") {
                      if(empty($_POST['nome'])) {
                        echo"<h3> Campo Nome Vazio, favor preencha para poder pesquisar!!! </h3>";
                      } else{
                        if($check_name != 1) {
                          echo"<h3> Nome não encontrado, favor verifique e tente novamente! </h3>";
                        }
                      }
                    };
                    if($acao == "search_cpf") {
                      if(empty($_POST['cpf'])) {
                        echo"<h3> Campo CPF Vazio, favor preencha para poder pesquisar!!! </h3>";
                      } else{
                        if($check_cpf != 1) {
                          echo"<h3> CPF não encontrado, favor verifique e tente novamente </h3>";
                        }
                      }
                    };
                    if($acao == "search_time") {
                      if(empty($_POST['select_time'])) {
                        echo"<h3> Campo Horario de Estudo Vazio, favor preencha para poder pesquisar!!! </h3>";
                      } else{
                        if($check_time != 1){
                          echo"<h3> Horario não encontrado no banco de dados, favor entrar em contato com o Administrador do Sistema! </h3>";
                        }
                      }
                    }
                ?>
              </div> <!-- final .cont-modal -->

              <a title="Fechar janela de confirmação" class="close">Entendi</a><br />
            </div>
            <!-- Máscara para cobrir a tela -->
            <div id="mask"></div>
        </div> <!-- final #boxes01 --> 

        <div id="boxes02">
            <div id="dialog02" data-id="<?php $id = $_GET['ID']; ?>" class="window02">
              <?php 
              $result = mysql_query("SELECT * FROM alunos WHERE Dia_Horario LIKE '%".$searched_time."%' " );

              $check_time = mysql_num_rows($result);
                if($check_time >= 1){
                   while($ln = mysql_fetch_array($result)) {
                    $radio = $ln['ID'];
                    $id = $ln['ID'];
                    $full_name = $ln['Nome_completo'];
                    $hora_estudo = $ln['Dia_Horario'];
                }
                }
              ?>
              <form>
                <lable for="txt-nome"> Nome:</lable><input type="txt" id="txt-nome" name="nome" class="txt" value="<?php echo $full_name; ?>" />
              </form>
              <a title="Fechar janela de confirmação" class="close02">X</a><br />
            </div>
            <!-- Máscara para cobrir a tela -->
            <div id="mask02"></div>
        </div> <!-- final #boxes01 --> 


        <div class="result-table">

          <div class="menu-top">
              <a href="" style="text-decoration:none;color:#fff;">
                <div  style="background-color:#06F;" class="bt-top">
                   Alunos 
                </div> <!-- .bt-table -->
              </a>

              <a href="http://www.dpaulatreinamentos.com/system/teste01/views/pages/colaboradores.php" style="text-decoration:none;">
                <div  class="bt-top">
                   Colabores 
                </div> <!-- .bt-table -->
              </a>
          </div> <!-- .menu-table -->

          <div id="form">
            <form id="form_nome" class="forms" method="post" action="?acao=search_name">
              <label for="txt-nome"><h3> Nome   </h3></label> <input type="text" name="nome" class="txt-medium txt" id="txt-nome" /> 
                <div class="tooltip">
                  <input type="submit" value="" class="sb-search-small bradius"/>
                  <span class="tooltiptext">
                    Pesquisar Por Nome
                  </span>
                </div> <!-- final .tooltip -->
            </form>
            <form id="form_cpf" class="forms" method="post" action="?acao=search_cpf">
              <label for="txt-cpf"><h3> CPF:    </h3></label> <input type="text" onkeypress="mascara(this, '###.###.###-##')"  name="cpf" maxlength="14" class="txt-small txt" id="txt-cpf" /> 
                <div class="tooltip">
                  <span class="tooltiptext">
                    Pesquisar Por CPF
                  </span>
                    <input type="submit" value="" class="sb-search-small bradius"/>         
                </div> <!-- final .tooltip -->

              <div class="tooltip">
                <a href=""> <div class="bt-more-small"> </div> </a>
                <span class="tooltiptext">
                  Cadastrar Aluno
                </span>
              </div> <!-- final .tooltip -->



            </form>
            <form id="form_search_class" class="forms" method="post" action="?acao=search_time">
              <lable for="select_time"> <h3> Dia e Horário: </h3>  </lable> <select id="select_time" class="bradius txt-time" name="select_time">
                  <option value="valor1"><?php 
                      $select_time_database = "SELECT * FROM horarios_aulas";
                      $check_time = mysql_query($select_time_database) or die (mysql_error());
                                 while($ln = mysql_fetch_array($check_time)) {
                                  $selected_time = $ln['Horario'];
                                   echo"<option value='$selected_time'> $selected_time </option>";
                                 }
                        ?>
                  </option> 
                </select>
              <div class="tooltip">
                <span class="tooltiptext">
                  Pesquisar Por horarios
                </span>
                <input type="submit" value="" class="sb-search-small bradius"/>
              </div> <!-- final .tooltip -->

              <div class="tooltip">
                <a href=""> <div class="bt-more-small"> </div> </a>
                <span class="tooltiptext">
                    Cadastrar novo horário de aula
                </span>
              </div> <!-- final .tooltip -->

            </form> 

         </div> <!-- final #forms -->

            <table class="com_table">
              <tbody>
                <tr>
                  <th scope="col">  </th>
                  <th scope="col"> ID </th>
                  <th scope="col">Nome </th>
                  <th scope="col">Hora e Dia Estudo</th>
                  <th scope="col">&nbsp;</th>
                  <th scope="col">&nbsp;</th>
                  <th scope="col">&nbsp;</th>
                  <th scope="col">&nbsp;</th>
                  <th scope="col">&nbsp;</th>
                </tr>


                <?php //seleciona toda a tabela

                    if($startaction == 3){
                      if($acao == "search_cpf") {
                        if(empty($_POST['cpf'])) {
                          echo'<script type="text/javascript">abre_modal( \'#dialog\' );</script>';
                        } else {
                        //pegar cpf via post
                        $cpf = $_POST['cpf'];
                        $cpf = preg_replace("/\D+/", "", $cpf);

                       $result = mysql_query("SELECT * FROM alunos WHERE CPF LIKE '%".$cpf."%' " );

                        $check_cpf = mysql_num_rows($result);
                          if($check_cpf >= 1){

                             while($ln = mysql_fetch_array($result)) {
                              $id = $ln['ID'];
                              $full_name = $ln['Nome_completo'];
                              $cargo = $ln['Cargo'];
                    ?>

                        <tr>
                          <a href=""><td> <?php echo $id; ?></td>  </a>
                          <td> <a name="modal01" href="#dialog01" onclick="$('#modal-container').load('<?php echo $id; ?>', function(){$('#dialog01').modal('show');})" > <?php echo $full_name; ?> </a> </td> 
                          <td> <?php echo $cargo; ?></td>
                        </tr>

                    <?php
                      } } else {
                        echo'<script type="text/javascript">abre_modal( \'#dialog\' );</script>';
                      }
                      }
                    }
                    }   

                    if($startaction == 4){
                      if($acao == "search_name") {
                        if(empty($_POST['nome'])) {
                          echo'<script type="text/javascript">abre_modal( \'#dialog\' );</script>';
                        } else {
                        //pegar nome via post
                        $nome = $_POST['nome'];
                        $result = mysql_query("SELECT * FROM alunos WHERE Nome_completo LIKE '%".$nome."%' " );

                        $check_name = mysql_num_rows($result);
                          if($check_name >= 1){

                             while($ln = mysql_fetch_array($result)) {
                              $id = $ln['ID'];
                              $full_name = $ln['Nome_completo'];
                              $hora_estudo = $ln['Dia_Horario'];

                  ?>


                       <tr>
                        <a href=""><td> <?php echo $id; ?></td></a>
                         <a href="#TD"> <td> <a data-id="" href='#dialog01' name="modal01" id="<?php  echo $id; ?>"> <?php echo $full_name; ?> </a> </td> </a>
                         <td> <?php echo $hora_estudo; ?></td>
                      </tr>




                    <?php

                      } } else {
                        echo'<script type="text/javascript">abre_modal( \'#dialog\' );</script>';

                      }
                      }
                    }

                    }

                    ?>

                <?php
                if($startaction == 5){
                      if($acao == "search_time") {
                        if(empty($_POST['select_time'])) {
                          echo'<script type="text/javascript">abre_modal( \'#dialog\' );</script>';
                        } else {
                        //pegar nome via post
                        $searched_time = $_POST['select_time'];
                        $result = mysql_query("SELECT * FROM alunos WHERE Dia_Horario LIKE '%".$searched_time."%' " );

                        $check_time = mysql_num_rows($result);
                          if($check_time >= 1){
                             while($ln = mysql_fetch_array($result)) {
                              $radio = $ln['ID'];
                              $id = $ln['ID'];
                              $full_name = $ln['Nome_completo'];
                              $hora_estudo = $ln['Dia_Horario'];

                  ?>

                    <div class="scroll-y">

                       <tr>
                        <td> <a data-toggle="modal02" data-target="#dialog02" href="#<?php echo $radio; ?>"> Clicar Aqui</a></td>
                        <a href=""><td> <?php echo $id; ?></td></a>
                         <a href="#TD"> <td> <a data-toggle="modal02" data-target="#dialog02"href='#dialog02' name="modal02" id="<?php  echo $id; ?>"> <?php echo $full_name; ?> </a> </td> </a>
                         <td> <?php echo $hora_estudo; ?></td>
                      </tr>

                    </div>


                    <?php

                      } } else {
                        echo'<script type="text/javascript">abre_modal( \'#dialog\' );</script>';

                      }
                      }
                    }

                    }

                    ?>


                </table>
          </tbody>
      </div> <!-- final .result-table -->

        </div> <!-- final .container -->     
  </body>
</html>
<?php 
    
asked by anonymous 29.12.2016 / 20:49

2 answers

0
  • Search results PHP : ... echo ("<a href='#' classe='nomecompleto' title='".$full_name"'>".$full_name."</a>"); ... Save the data on the client side this way, so you do not need to make a second query when you want to edit.

  • jQuery + LocalStorage By clicking the student's name, it is copied to the localStorage Code jquery : $('document').ready(function (){ $('.nomecompleto').click(function(){ localStorage.setItem('nome', $(this). attr ('title')); }); }); The student's name has now been saved on the localStorage

  • On the modal or anywhere else Assuming #editarnome is id of input to edit the name, automatically loads the student's name saved in the localStorage $('#editarnome').val() = localStorage.getItem('nome');

I hope I have helped

    
29.12.2016 / 22:11
0

I think you should do the following to see all the results

   <?php 
              $result = mysql_query("SELECT * FROM alunos WHERE Dia_Horario LIKE '%".$searched_time."%' " );
$check_time = mysql_num_rows($result);
echo "<ul>";  // adicionado
if($check_time >= 1){
                   while($ln = mysql_fetch_array($result)) {
                   echo "<li>".$ln['Nome_completo']."</li>";   //adicionado   
                }
                }
echo "</ul>"; // adicionado
              ?>              
    
06.01.2017 / 12:59