Passing data from one row (table) to another PHP page

2

I seek your help with the following case. I have an HTML table which I load dynamically from mysql, each row of the table has a button with which I intend to take the data of the selected row to another page and collect the data in a form and for this I use a hidden input. The problem I have is that it always brings me the last record of the table to the next page and not the one that I select. This is the code of my table:

<form action="servicio.php" method="post">
                    <table class="table table-striped">
                            <thead>
                                <th>Ticket</th>
                                <th>Nombre</th>

                            </thead>
                            <tbody>
                                <?php foreach($consultaTicket as $datos): ?>
                                <tr>
                                    <td>
                                        <?php echo $datos->getTicket(); ?>
                                    </td>
                                    <td>
                                        <?php echo $datos->getCliente(); ?>
                                    </td>
      <input type="hidden" name="ticket" value="<?php echo $datos->getTicket(); ?>">
      <td><input type="submit" class="btn btn-primary btn-sm" value="Seleccionar"></td>
                                    <?php 
                        endforeach;
                        ?>
                                </tr>
                            </tbody>
                        </table>
</form>

Thanks for the help you can give me, I do not know what to do.

    
asked by wico 17.07.2018 в 15:39
source

1 answer

2

Each one must be unique, you can use unique identifiers or independent forms by tuple so that the submit sends the data of its corresponding form. Since you only want the tuple data, I'll give you an example with the second case.

<table class="table table-striped">
   <thead>
     <th>Ticket</th>
     <th>Nombre</th>
   </thead>
   <tbody>
     <?php foreach($consultaTicket as $datos): ?>
       <form action="servicio.php" method="post">
         <tr>
           <td>
              <?php echo $datos->getTicket(); ?>
           </td>
           <td>
              <?php echo $datos->getCliente(); ?>
           </td>
           <input type="hidden" name="ticket" value="<?php echo $datos->getTicket(); ?>">
           <td><input type="submit" class="btn btn-primary btn-sm" value="Seleccionar"></td>
        </form>
      <?php endforeach; ?>
    </tr>
  </tbody>
</table>
    
answered by 17.07.2018 / 15:55
source