Change table in mysql

Asked

Viewed 349 times

1

I have the following situation.

A table that displays the searched results in mysql, and within this table I have a column where the edit button is. How do I get this button to edit the content shown on that line?

I’m wearing the bow tie while to display them and, as far as I know, the ribbon while does not count what was displayed/found first or second. Right?

For example; in the code below I used mysql to search in the table "request" everything that has the word "waiting..." in the status column. The noose while will display one by one in order you find, and display more or less like this:

ID | Produto   | Valor | Cód. Pedido | Situação      | Editar
 1 | Produto 1 | 1.00  | 321         | Aguardando... | Botão Editar

And so it goes, ID 2, Product 2 and so on.

How could I make the button at the end of the table edit inside mysql the row it is on?

<section class="news">
        <div class="page-reader">
            <h3>Lista de Pedidos <small>atualizado em <?= date("d/m/Y") ?></small></h3>
        </div>
        <table class="table table-striped">
            <tr>
                <td>ID</td>
                <td>Produto</td>
                <td>Valor</td>
                <td>Código do Pedido</td>
                <td>Situação</td>
                <td>Editar Pedido</td>

                <!-- Coloca os dados em um Array -->
                <?php 
                while ($resultado = mysqli_fetch_assoc($dados)) { ?>
            </tr>
                <td><?= $resultado['id']; ?></td>
                <td><?= $resultado['produto']; ?></td>
                <td><?= "R$ ". number_format($resultado['valor'],2); ?></td>
                <td><?= $resultado['pedido']; ?></td>
                <td><?= $resultado['status']; ?></td>
                <td><button type="button" class="btn btn-primary">Confirmar</button> <button class="btn btn-danger">Cancelar</button></td>
                <?php
                }
                 ?>
            </table>
    </section>
  • Edit which field?

  • Edit the Status field. the commands for editing I know and can do, but I only know if I get the variable sent via post or get.

  • Then you have a list of N records and all with one button to change the status only, correct, with click and update without Reload on the page. You can do this with jQuery.

  • See if that reply help you.

  • Papa Charlie, I tried to follow the topic you gave me but I couldn’t and I don’t think it’s what I need. I think you misunderstood my request.

  • 1

    I don’t know what might have generated that "offensive" warning, it might be some system bug. If it happens again, please take a screenshot and signal the post indicating the image link, so a moderator can evaluate. I left the question as Victor had left it, because I considered it the best state of it. As for the answer, please be patient. The people who help here are all volunteers, but sooner or later you get an answer. Thank you.

Show 1 more comment

1 answer

1

Good Rafael, the easiest alternative would be to generate an edit button for each line. That is to say.

Generate a button on while or a <a> and pass the edit url along with the id returned in query

Example:

<a href="editar.php?linha=$resultado['id']" />

Browser other questions tagged

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