How to assign a number to each placement

2

I'm doing a page where it shows the rankings of users with more X and Y, everything is shown inside the site in a table where there is the name of each user and the amount of X he has, but I do not know how to put for example: 1 or 1. Robson 100 (Diamonds), ie I can not put the first column with the settings, to select the users and to show how much each one has I got, all that is left is to insert the settings.

<?php
    # conectare la base de datos
    require ('../../global.php');

    $action = (isset($_REQUEST['action'])&& $_REQUEST['action'] !=NULL)?$_REQUEST['action']:'';
    if($action == 'ajax'){
        require ('../../hk/pagination.php'); //incluir el archivo de paginación
        //las variables de paginación
        $page = (isset($_REQUEST['page']) && !empty($_REQUEST['page']))?$_REQUEST['page']:1;
        $per_page = 10; //la cantidad de registros que desea mostrar
        $adjacents  = 4; //brecha entre páginas después de varios adyacentes
        $offset = ($page - 1) * $per_page;
        //Cuenta el número total de filas de la tabla*/
        $count_query   = $link->query("SELECT count(*) AS numrows FROM usuarios ");
        if ($row= mysqli_fetch_array($count_query)){$numrows = $row['numrows'];}
        $total_pages = ceil($numrows/$per_page);
        $reload = 'rank.php';
        //consulta principal para recuperar los datos
        $query = $link->query("SELECT * FROM usuarios  order by diamantes DESC LIMIT $offset,$per_page");

        if ($numrows>0){
            ?>
<table class="table table-striped table-hover ">
              <thead>
                <tr>
                              <th>Colocação</th>
                              <th><?php echo $lang[27]; ?></th>
                              <th>Diamantes</th>
                </tr>
            </thead>
            <tbody>
            <?php
            while($row = mysqli_fetch_array($query)){
                ?>
                <tr>
                              <td>NESSA LINHA NO ANTIGO CODIGO (De onde copiei) Ficaria o ID do usuário, porém gostaria de por a colocação</td>
                              <td><?php echo "$row[username]"; ?></td>
                              <td><?php echo "$row[diamantes]"; ?></td>
                </tr>
                <?php
            }
            ?>
            </tbody>
        </table>
        <div class="table-pagination pull-right">
            <?php echo paginate($reload, $page, $total_pages, $adjacents);?>
        </div>

            <?php

        } else {
            ?>
            <div class="alert alert-warning alert-dismissable">
              <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
              <?php echo $lang[195]; ?>
            </div>
            <?php
        }
    }
?>
    
asked by anonymous 30.06.2018 / 02:48

1 answer

2

Create a variable before while to increment in the loop.

For example:

<?php
$x = 1;
while($row = mysqli_fetch_array($query)){
    ?>
    <tr>
                  <td><?php echo $x.'&ordm;'; ?></td>
                  <td><?php echo "$row[username]"; ?></td>
                  <td><?php echo "$row[diamantes]"; ?></td>
    </tr>
    <?php
   $x++;
}
    ?>

At every turn in the while, $x is incremented by +1 , showing 1st, 2nd, 3rd, and so on.

    
30.06.2018 / 03:16