Problem with $ _SESSION with $ _GET displaying in unexpected result table

0
<?php 

    session_start();

    if(isset($_GET['nome'])){

        $_SESSION['lista'][] = $_GET['nome'];
        $_SESSION['lista'][] = $_GET['telefone'];
        $_SESSION['lista'][] = $_GET['email'];

    }

    $lista = array();

    if(isset($_SESSION['lista'])){

        $lista = $_SESSION['lista'];


    }

?>

...

        <table style="width:100%" border="3">

            <thead>
                <tr>
                    <th>Nome</th>
                    <th>Telefone</th>
                    <th>E-Mail</th>
                </tr>
            </thead>

            <tbody>

                <?php foreach($lista as $lis): ?>
                    <tr>

                        <td><?=$lis?></td>
                        <td><?=$lis?></td>
                        <td><?=$lis?></td>

                    </tr>
                    <?php endforeach; ?>
            </tbody>


        </table>

...

At the time of displaying in the table one line is occupied by names, and the next line by telephones, how can I solve this so that a line has name, phone and email?

    
asked by anonymous 01.07.2017 / 00:36

1 answer

1

How many records will be composed by name, phone and email, what you need to do is:

$_SESSION["lista"][] = array(
    "nome" => $_GET["nome"],
    "telefone" => $_GET["telefone"],
    "email" => $_GET["email"]
);

So, each session item will be an array with all three values. When viewing, use foreach , as you already do, and access values with named indexes:

$lista = $_SESSION["lista"];

<?php foreach($lista as $lis): ?>
    <tr>
        <td><?= $lis["nome"] ?></td>
        <td><?= $lis["telefone"] ?></td>
        <td><?= $lis["email"] ?></td>
    </tr>
 <?php endforeach; ?>
    
01.07.2017 / 01:01