PHP: Take value of an arrangement inside a while and send it to another page

1

I have a problem. I need help to traverse a while and take the value of an array that is full of data from a database. I need to take some value and send the data of that arrangement to another page.

I leave my code here:

<?php while($row = $execute->fetch_assoc()){ ?>
    <tbody>
        <form class="" action="promotor registro general detalles.php" method="post">
            <tr>
                <td> <?php echo $row['fecha']; ?></td>
                <td> <?php echo $row['entrada']; ?></td>
                <td> <?php echo $row['salida']; ?></td>
                <td> <input type="submit" name="detalles" value="Detalles"></td>
            </tr>
        </form>
    </tbody>
<?php } ?>

What I specifically need is to know how, by clicking on the details button, the record of that button is taken.

I have an idea to use the $ _SESSION , but I do not know how to give it the specific value of that record.

I hope I have been specific.

    
asked by Esteban Trevino Zwingil 01.08.2018 в 18:17
source

2 answers

2

I imagine that the data that you tell us should have an id what you should do is put that id as a variable in your url like this:

<?php while($row = $execute->fetch_assoc()){ ?>
    <tbody>
        <form class="" action="promotor registro general detalles.php?var1=<?php echo $row['id_del_registro']; ?>" method="post">
            <tr>
                <td> <?php echo $row['fecha']; ?></td>
                <td> <?php echo $row['entrada']; ?></td>
                <td> <?php echo $row['salida']; ?></td>
                <td> <input type="submit" name="detalles" value="Detalles"></td>
            </tr>
        </form>
    </tbody>
<?php } ?>

Then in your file detalles.php you receive it like this

$id = $_GET["var1"];

You can now make your query with that id to bring all the information you need for your detail

    
answered by 01.08.2018 / 18:44
source
2

The easiest way is to send the registration identifier by GET to the other page by using a href in the following way:

<?php while($row = $execute->fetch_assoc()){ ?>
<tbody>
    <tr>
        <td> <?php echo $row['fecha']; ?></td>
        <td> <?php echo $row['entrada']; ?></td>
        <td> <?php echo $row['salida']; ?></td>
        //Aquí utilizas el id del registro para identificarlo
        <td><a href="promotor registro general detalles.php?id_registro=<?php echo $row['salida']; ?>" role="button">Detalles</a></td>
    </tr>
</tbody>
<?php } ?>

In your file promotor general registration details.php , you receive it in the following way:

$id = $_GET['id_registro'];

With this you can do what you want with the selected record.

    
answered by 01.08.2018 в 18:31