Get Foreach ID on same page with Session

Asked

Viewed 122 times

0

Next, I’m developing a way to update the notification date in the bank, only to update this date I need the registration ID. I can bring this ID from the bank without problem, the problem is when the guy clicks on the div, I don’t know how to identify the id he clicked on. I tried to use $_Session (I did it once only it sends to another page, then rolled), but it is overwriting the values in the variable. (The id is from the registry, not from Div).

Codes:

    foreach ($notificacoes as $notificacao): 
    ?>    

    <center>
    <?php
        echo $notificacao['datareg'];
        if(!empty($notificacao['datareg'])){
            echo '<div id="'. $div . $cont . '" class="visualizado" onclick="visualizarNt()">';
        } else {
            echo '<div id="'. $div . $cont .'" class="naovisualizado" onclick="visualizarNt()">';
        }                                                                                            
    ?>       
            <table border = "1">

                <tr>
                    <td>Foto</td>
                    <td>Nome</td>
                    <td>Sobrenome</td>
                    <td>Detalhes</td>
                    <td>Data esperada</td>
                    <td>Perfil</td>
                    <td>Cancelar</td>
                    <?php
                    if ($notificacao['estadoContrato'] != 'ConfirmadoTecnico') {
                        echo '<td>Atualizar</td>';
                    }
                    ?>
                </tr>
                <tr>
                    <td><img src="<?php echo $notificacao['foto'] ?>" width="40px" height="40px"</td>
                    <td><?php echo $notificacao['nome'] ?></td>
                    <td><?php echo $notificacao['sobrenome'] ?></td>
                    <td><?php echo $notificacao['detalhes'] ?></td>                    
                    <td><?php echo $notificacao['data_acertada'] ?></td>
                    <td><a href="pag_perfilAbertoTec.php">Visitar</a></td>
                    <td><a href="" onclick="cancelar(); return false;">Cancelar</a></td>
                    <?php
                    if ($notificacao['estadoContrato'] != 'ConfirmadoTecnico') {
                        echo '<td><a href="" onclick="atualizar(); return false;">Confirmar</a></td>';
                    }

                    $_SESSION['idContrato'] = $_SESSION['datareg'];
                    // Tentei assim, mas ele está sobrepondo..
                    ?>
                </tr>
            </table>
            <?php $cont++; ?>
        </div></center>
    <?php
endforeach;
  • I don’t quite understand what you need; your explanation is very confusing. Try to be more direct and descriptive.

  • By doing Foreach, I can get the data from each record, right? in case I’m not able to make a way to separate these id’s, because if I put in the session the id’s will be overwritten..

  • What’s the point of separating the Ids. It is necessary that you explain what you want to do so that we can help you; from what I understand you get the ID’s, but I don’t understand when you refer to "separate these id... if I put in the session the id will be overlaid".

  • I need the ID to update the date in the BD when the user clicks on the div. Only I don’t know how to get this id, first as said, if I put it in the session it will be overwritten and second because the code that updates is out of foreach, then I can’t use the $notification variable[]

  • You have two options. Use javascript to retrieve the element ID, or via the link make a request to a PHP page that will receive the method. If it is a dynamic content, I suggest using javascript.

No answers

Browser other questions tagged

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