Classification system

3

I would like to make the positions appear. I have no idea how. Below I'll be giving a demo and my code

<?phpinclude("./configs/dados.php");
$ranking = "SELECT * FROM usuarios ORDER BY pontos_total  Desc LIMIT 3,10";
$limiteranking = mysql_query("$ranking");
while ($ranking = mysql_fetch_array($limiteranking)) {  
$nomeran = $ranking['login'];
$pontosran = $ranking['pontos_total'];
?>      




    <tr style="background:#d3a298">
      <th scope="row"><center>4º</th></center>
      <td style="color:#383838"><?php echo $nomeran; ?></td>
      <td style="color:#383838"><?php echo $pontosran; ?></td>
    </tr>

<?php } ?>

* Code only from 4th down. As you can see, I would like to see 4th, 5th, 6th

    
asked by anonymous 16.09.2016 / 23:56

2 answers

2

Do this:

<?php
include("./configs/dados.php");
$posicao = 4;
$ranking = "SELECT * FROM usuarios ORDER BY pontos_total  Desc LIMIT 3,10";
$limiteranking = mysql_query("$ranking");
while ($ranking = mysql_fetch_array($limiteranking)) {  
$nomeran = $ranking['login'];
$pontosran = $ranking['pontos_total'];
?>      




    <tr style="background:#d3a298">
      <th scope="row"><center><?php echo $posicao;?>º</th></center>
      <td style="color:#383838"><?php echo $nomeran; ?></td>
      <td style="color:#383838"><?php echo $pontosran; ?></td>
    </tr>

<?php $posicao++; } ?>

Explaining the code:

It creates a variable with the value of 4 which is the first position. Whenever he makes a new loop, that is, when he picks up a new record he adds +1 thus always leaving the current position of the user in the ranking.

Note: If you want to appear as 1st, 2nd, 3rd ... Change $posicao = 4; to $posicao = 1;

    
17.09.2016 / 00:02
2

Create a variable $i out of the loop by storing how many times the block has been iterated (repeated). At each iteration, you add a drive to this variable:

<?php
    include("./configs/dados.php");
    $ranking = "SELECT * FROM usuarios ORDER BY pontos_total  Desc LIMIT 3,10";
    $limiteranking = mysql_query("$ranking");

    $i = 0;
    while ($ranking = mysql_fetch_array($limiteranking)) {  
        $i = $i + 1;

        $nomeran = $ranking['login'];
        $pontosran = $ranking['pontos_total'];
?>      

        <tr style="background:#d3a298">
          <th scope="row"><center><?php echo $i; ?>º</th></center>
          <td style="color:#383838"><?php echo $nomeran; ?></td>
          <td style="color:#383838"><?php echo $pontosran; ?></td>
        </tr>

<?php
    }
?>
    
17.09.2016 / 00:07