Pass an id to another page via a foreach

Asked

Viewed 40 times

-2

Next: when the user clicks on "apply", he goes to another page and there I will work with the id of the record he clicked, only there is born the problem, I do not know how to do it. code:

page_list:

                            foreach ($chamados as $chamado):
                                    ?>
                                <tr>
                                    <td><?php echo $chamado['data_solicitado'] ?></td>
                                    <td><?php echo $chamado['detalhes'] ?></td>
                                    <td><?php echo $chamado['logradouro'] ?></td>
                                    <td><?php echo $chamado['estado'] ?></td>
                                    <td><?php echo $chamado['cidade'] ?></td>
                                    <td><?php echo $chamado['bairro'] ?></td>
                                    <td><?php echo $chamado['num'] ?></td>
                                    <td><?php echo $chamado['complemento'] ?></td>    
                                    <td><?php echo $chamado['ddd'] ?></td>
                                    <td><?php echo $chamado['numero'] ?></td>
                                    <td><?php echo $chamado['nome'] ?></td>
                                    <td><?php echo $chamado['sobrenome'] ?></td>
                                    <td><a onclick="verificaAlistamento()">Candidatar-se</a></td>
                                    <?php 
                                        $chamado['id_contrato'];
                                    ?>
                                </tr>
                                <?php
                            endforeach;

pag_verifies

    $user = $_SESSION['nome'];
    $idContrato = $_POST[$id_contrato];
    $cpf = pegaCpfUsuarioLogado($conexao, $user);
    if(verificaCandidatura($conexao, $cpf)){
?>
    <script>deuRuim()</script>
<?php
    candidatarSe($conexao, $cpf, $idContrato);
    header("location: pag_menuTecnico.php");
    } else {
?>
    <script>deuBom()</script>
<?php
    header("location: pag_menuTecnico.php");
    }

I’ve tried to do so: https://forum.imasters.com.br/topic/307200-pegar-o-indice-do-array-em-um-foreach/

only that there stopped to bring the calls in open

1 answer

-1


Just you save in the Session:

pag_listar_called.php

$_SESSION['id_contrato'] = $chamado['id_contrato'];

On the other page, you can use it normally:

pag_verifies.php

$idContrato = $_SESSION['id_contrato'];

In the end, don’t forget to destroy the session with unset:

session_destroy ();
unset($_SESSION['id_contrato']);
  • Thanks!! Solved my problem.

  • Dispose, my friend ^^

Browser other questions tagged

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