Pergunta

I'm having trouble to make a 'counting' system in PHP. I would like it to be like this:

  1. Clark
  2. Maikel
  3. Steven
  4. .....

My problem is that I can't make this because the names are coming through a while loop, so I don't know how to make it now. My code is as follows:

<?php
    while($score = $highscore->fetch_array())
    {
        // Systeem voor levels.
        if($score['clicks'] >= 0 && $score['clicks'] <= 49)
        {
            $level = 'Level 1';
        }
        elseif($score['clicks'] >= 50 && $score['clicks'] <= 99)
        {
            $level = 'Level 2';
        }
        else if($score['clicks'] >= 100 && $score['clicks'] <= 199)
        {
            $level = 'Level 3';
        }
        else if($score['clicks'] >= 200 && $score['clicks'] <= 349)
        {
            $level = 'Level 4';
        }
        else if($score['clicks'] >= 350 && $score['clicks'] <= 499)
        {
            $level = 'Level 5';
        }
        else if($score['clicks'] >= 500 && $score['clicks'] <= 749)
        {
            $level = 'Level 6';
        }
        else if($score['clicks'] >= 750 && $score['clicks'] <= 999)
        {
            $level = 'Level 7';
        }
        else if($score['clicks'] >= 1000 && $score['clicks'] <= 1499)
        {
            $level = 'Level 8';
        }
        else if($score['clicks'] >= 1500 && $score['clicks'] <= 1999)
        {
             $level = 'Level 9';
        }
        else if($score['clicks'] >= 2000 && $score['clicks'] <= 2999)
        {
             $level = 'Level 10';
        }
        else if($score['clicks'] == 3000)
        {
             $level = 'Level 11';
        }
        else if($score['clicks']> 3000)
        {
             $level= 'Level ' . floor(($score['clicks']/1000)+8);
        }
    ?>
    <tr>
      <td><?php echo $score['name']; ?></td>
      <td><?php echo $score['clicks']; ?></td>
      <td><?php echo $level; ?></td>
    </tr>
    <?php
    }
    ?>

So my question is how can I make a counting system that count up till 100? It needs to go before .

Sorry for the bad English, thank you for helping!

Foi útil?

Solução

You can try something like this:

<?php
    $counter = 0;
    while($score = $highscore->fetch_array())
    {
        $counter++;

        //Your content

        if ( $counter >= 100 ) {
            break;
        }
    }

This should break your while when it reaches 100.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top