Picking up a variable from the foreach

1

I'm breaking my head into a problem. I hope you can help me please. I am listing all records in the database. I need to get the id of the line as the click. I'm just getting the ID of the first line, when I click on the next line the variable gives me the 1st record again.

* I took all the css and unnecessary PHp of the code to be quick and easy to understand:)

index

<table class="table table-hover">
                            <thead>
                                <tr>
                                    <th scope="col">Nº do Cliente</th>
                                    <th scope="col">Nome</th>

                                </tr>
                            </thead>
                            <tbody>

                                <?php

                                $Mostrar = new Crud();
                                foreach ($Mostrar->Listar() as $rs) {
                                    ?>


               <tr>
               <td><?php echo $rs['cli_id']; ?></td> <!--PRECISO DESSA VARIAVEL -->
                                        <td><?php echo $rs['cli_nome']; ?></td>

                                    </tr>
                                    <?php include 'includes/clientes/cadastrarMoto.php'; ?> <!--AQUI FICA O MODAL PRA APRESENTAR O ID -->


                                    <tr>
                                        <td colspan="6">
                                            <div class="pull-left">
                                                    <span class="material-icons adicionar" title="Motos" data-balao="tooltip"  data-toggle="modal" data-target="#cadastrarMoto">storage</span></div> <!--CLICANDO AQUI VAI PARA UM MODAL -->




                                        </td>
                                    </tr>


                                    <?php
                                }
                                ?>
                            </tbody>
                        </table>

registerMoto.php

<div class="modal fade">
.........
<?php echo $rs['cli_id']; ?>
    
asked by anonymous 27.06.2018 / 07:03

1 answer

2

You can add in the value "date" of the link that opens the modal

<span class="material-icons adicionar" title="Motos" data-balao="tooltip"  data-toggle="modal" data-target="#cadastrarMoto" data-value-id="<?= $rs['cli_id']; ?>">storage</span>

and in the modal you get the value directly with javascript

There are examples here link

    
27.06.2018 / 17:34