How to update a column of data each time someone enters a page? This is so they can show in the table

Asked

Viewed 25 times

-1

The error is in the code snippet where there is the $update variable below.

inserir a descrição da imagem aqui

I use Mysql and have this table and the goal is to show in an html table the totalranking points. When someone earns points I always get the points in the ranking and when they lose, the points in menosranking are assigned. So in table html I ask to show totalranking that would be "totalranking = the ranking - menosranking". So far so good. But note that totalranking only lives outdated, so I did in PHP something for it to update the entire column totalranking every time someone entered the page, but it only worked once and this update does not happen when someone accesses the page. The code is this:

table class="table table-striped">
    <thead>
        <tr>
            <th scope="col">Posição</th>
            <th scope="col">Nome</th>
            <th scope="col">Pontuação</th>
        </tr>
    </thead>
    <?php
    $atualiza = mysqli_query($conexao, "UPDATE 'login_usuario' SET 'totalranking' = ranking - menosranking"); //deveria atualizar o banco de dados

    $query = mysqli_query($conexao, "SELECT usuario, totalranking FROM login_usuario ORDER BY totalranking DESC LIMIT 10"); 

    $lista = 0;
    while ($tabela = mysqli_fetch_array($query)) {
        $lista++;
    ?>

    <tbody class="table-striped"> 
        <tr>
            <th scope="row"><?php echo $lista; ?></th>
            <td><?php echo $tabela['usuario']; ?></td>
            <td><?php echo $tabela['totalranking']; ?></td>
        </tr>

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

grateful,

1 answer

0


I got it after a few tests.

"UPDATE login_usuario SET totalranking = ranking - menosranking"

It was a problem with the single quotes. But there is the question and the answer in case someone has a similar question.

Browser other questions tagged

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